Introducing a new function for binding and unbinding a JBOD device, which is used before formatting and in case we need to rollback because of a failure. This prevents overlength errors when a read is issued to the disk during formatting.
Signed-off-by: Heitor Ricardo Alves de Siqueira <hal...@linux.vnet.ibm.com> --- iprconfig.c | 11 +++++++++++ iprlib.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ iprlib.h | 3 +++ 3 files changed, 58 insertions(+) diff --git a/iprconfig.c b/iprconfig.c index c4499a6d3c1c..c9bea28b9fd1 100644 --- a/iprconfig.c +++ b/iprconfig.c @@ -8862,12 +8862,23 @@ int send_dev_inits(i_container *i_con) continue; } + /* unbind device */ + if (ipr_jbod_sysfs_bind(cur_dev_init->dev, + IPR_JBOD_SYSFS_UNBIND)) + syslog(LOG_ERR, "Could not unbind %s: %m\n", + cur_dev_init->dev->dev_name); + /* Issue format */ status = ipr_format_unit(cur_dev_init->dev); /* FIXME Mandatory lock? */ if (status) { /* Send a device reset to cleanup any old state */ rc = ipr_reset_device(cur_dev_init->dev); + if (ipr_jbod_sysfs_bind(cur_dev_init->dev, + IPR_JBOD_SYSFS_BIND)) + syslog(LOG_ERR, + "Could not bind %s: %m\n", + cur_dev_init->dev->dev_name); cur_dev_init->do_init = 0; num_devs--; diff --git a/iprlib.c b/iprlib.c index 6e5a487da3c6..38b94bb33341 100644 --- a/iprlib.c +++ b/iprlib.c @@ -9986,3 +9986,47 @@ int ipr_query_io_dev_port(struct ipr_dev *dev, struct ipr_query_io_port *io_port return rc; } +/** + * ipr_jbod_sysfs_bind - + * @dev: ipr dev struct + * @op: sysfs operation + * + * Returns: + * 0 if success / non-zero on failure + **/ +int ipr_jbod_sysfs_bind(struct ipr_dev *dev, u8 op) +{ + struct ipr_dev *mp_dev; + int rc, fd, size; + char *sysfs_device_name; + + sysfs_device_name = dev->scsi_dev_data->sysfs_device_name; + size = strnlen(sysfs_device_name, sizeof(sysfs_device_name)); + + if (op == IPR_JBOD_SYSFS_BIND) { + fd = open("/sys/bus/scsi/drivers/sd/bind", O_WRONLY); + } else if (op == IPR_JBOD_SYSFS_UNBIND) { + fd = open("/sys/bus/scsi/drivers/sd/unbind", O_WRONLY); + } else { + fd = -1; + errno = ENOTSUP; + } + if (fd < 0) + return errno; + + rc = write(fd, sysfs_device_name, size); + if (rc < 0) + return errno; + + mp_dev = find_multipath_jbod(dev); + if (mp_dev) { + sysfs_device_name = mp_dev->scsi_dev_data->sysfs_device_name; + size = strnlen(sysfs_device_name, sizeof(sysfs_device_name)); + rc = write(fd, sysfs_device_name, size); + if (rc < 0) + return errno; + } + + close(fd); + return 0; +} diff --git a/iprlib.h b/iprlib.h index cf6bf7989562..51e47abe0e92 100644 --- a/iprlib.h +++ b/iprlib.h @@ -1279,6 +1279,9 @@ struct ipr_mode_page_28_scsi_dev_bus_attr { #define IPR_MAX_XFER_RATE 320 #define IPR_SAFE_XFER_RATE 160 +#define IPR_JBOD_SYSFS_UNBIND 0 +#define IPR_JBOD_SYSFS_BIND 1 + /* Internal return codes */ #define RC_SUCCESS 0 #define RC_FAILED -1 -- 2.4.3 ------------------------------------------------------------------------------ _______________________________________________ Iprdd-devel mailing list Iprdd-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/iprdd-devel