]> git.itanic.dy.fi Git - linux-stable/commitdiff
s390/dasd: add device ping attribute
authorStefan Haberland <sth@linux.ibm.com>
Tue, 20 Sep 2022 19:26:16 +0000 (21:26 +0200)
committerJens Axboe <axboe@kernel.dk>
Wed, 21 Sep 2022 14:32:51 +0000 (08:32 -0600)
Add a function to check if a device is accessible.
This makes mostly sense for copy pair secondary devices but it will work
for all devices.

The sysfs attribute ping is a write only attribute and will issue a NOP
CCW to the device.
In case of success it will return zero. If the device is not accessible
it will return an error code.

Signed-off-by: Stefan Haberland <sth@linux.ibm.com>
Reviewed-by: Jan Hoeppner <hoeppner@linux.ibm.com>
Link: https://lore.kernel.org/r/20220920192616.808070-8-sth@linux.ibm.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/s390/block/dasd_devmap.c
drivers/s390/block/dasd_eckd.c
drivers/s390/block/dasd_eckd.h
drivers/s390/block/dasd_int.h

index ca5c9e9636628767ab5bc0c5ed47f14db0372661..2f7341412ea9a447c16aa3121081647f6da3c8ca 100644 (file)
@@ -2234,6 +2234,40 @@ dasd_copy_role_show(struct device *dev,
 }
 static DEVICE_ATTR(copy_role, 0444, dasd_copy_role_show, NULL);
 
+static ssize_t dasd_device_ping(struct device *dev,
+                               struct device_attribute *attr,
+                               const char *buf, size_t count)
+{
+       struct dasd_device *device;
+       size_t rc;
+
+       device = dasd_device_from_cdev(to_ccwdev(dev));
+       if (IS_ERR(device))
+               return -ENODEV;
+
+       /*
+        * do not try during offline processing
+        * early check only
+        * the sleep_on function itself checks for offline
+        * processing again
+        */
+       if (test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
+               rc = -EBUSY;
+               goto out;
+       }
+       if (!device->discipline || !device->discipline->device_ping) {
+               rc = -EOPNOTSUPP;
+               goto out;
+       }
+       rc = device->discipline->device_ping(device);
+       if (!rc)
+               rc = count;
+out:
+       dasd_put_device(device);
+       return rc;
+}
+static DEVICE_ATTR(ping, 0200, NULL, dasd_device_ping);
+
 #define DASD_DEFINE_ATTR(_name, _func)                                 \
 static ssize_t dasd_##_name##_show(struct device *dev,                 \
                                   struct device_attribute *attr,       \
@@ -2292,6 +2326,7 @@ static struct attribute * dasd_attrs[] = {
        &dev_attr_fc_security.attr,
        &dev_attr_copy_pair.attr,
        &dev_attr_copy_role.attr,
+       &dev_attr_ping.attr,
        NULL,
 };
 
index d4d3bd33553b01b420be8e0fc7d6ce16cd900a0a..95b0cd071cadfc1055bd50496a55ff03ffa8d0db 100644 (file)
@@ -6277,6 +6277,49 @@ static int dasd_eckd_query_pprc_status(struct dasd_device *device,
        return rc;
 }
 
+/*
+ * ECKD NOP - no operation
+ */
+static int dasd_eckd_nop(struct dasd_device *device)
+{
+       struct dasd_ccw_req *cqr;
+       struct ccw1 *ccw;
+       int rc;
+
+       cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 1, device, NULL);
+       if (IS_ERR(cqr)) {
+               DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
+                               "Could not allocate NOP request");
+               return PTR_ERR(cqr);
+       }
+       cqr->startdev = device;
+       cqr->memdev = device;
+       cqr->block = NULL;
+       cqr->retries = 1;
+       cqr->expires = 10 * HZ;
+
+       ccw = cqr->cpaddr;
+       ccw->cmd_code = DASD_ECKD_CCW_NOP;
+       ccw->flags |= CCW_FLAG_SLI;
+
+       cqr->buildclk = get_tod_clock();
+       cqr->status = DASD_CQR_FILLED;
+
+       rc = dasd_sleep_on_interruptible(cqr);
+       if (rc != 0) {
+               DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
+                               "NOP failed with rc=%d\n", rc);
+               rc = -EOPNOTSUPP;
+       }
+       dasd_sfree_request(cqr, cqr->memdev);
+       return rc;
+}
+
+static int dasd_eckd_device_ping(struct dasd_device *device)
+{
+       return dasd_eckd_nop(device);
+}
+
 /*
  * Perform Subsystem Function - CUIR response
  */
@@ -6899,6 +6942,7 @@ static struct dasd_discipline dasd_eckd_discipline = {
        .pprc_status = dasd_eckd_query_pprc_status,
        .pprc_enabled = dasd_eckd_pprc_enabled,
        .copy_pair_swap = dasd_eckd_copy_pair_swap,
+       .device_ping = dasd_eckd_device_ping,
 };
 
 static int __init
index 4da9d0331be544d3c728f955ab719a7e002648d0..f9299bd184ba80098375b06981921844670522bf 100644 (file)
@@ -13,6 +13,7 @@
 /*****************************************************************************
  * SECTION: CCW Definitions
  ****************************************************************************/
+#define DASD_ECKD_CCW_NOP               0x03
 #define DASD_ECKD_CCW_WRITE             0x05
 #define DASD_ECKD_CCW_READ              0x06
 #define DASD_ECKD_CCW_WRITE_HOME_ADDRESS 0x09
index 3c55c29155efcf4734860731421305db4f4dfd58..c7223c4eba5246a92e6a98dc54719ab45701476b 100644 (file)
@@ -439,6 +439,7 @@ struct dasd_discipline {
        int (*pprc_status)(struct dasd_device *, struct dasd_pprc_data_sc4 *);
        bool (*pprc_enabled)(struct dasd_device *);
        int (*copy_pair_swap)(struct dasd_device *, char *, char *);
+       int (*device_ping)(struct dasd_device *);
 };
 
 extern struct dasd_discipline *dasd_diag_discipline_pointer;