]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
sd: Allow protection_type to be overridden
authorMartin K. Petersen <martin.petersen@oracle.com>
Wed, 13 Jun 2012 04:12:35 +0000 (00:12 -0400)
committerMartin K. Petersen <martin.petersen@oracle.com>
Wed, 13 Jun 2012 04:12:35 +0000 (00:12 -0400)
We have encountered a few devices that misbehaved when operating in T10
PI mode. Allow T10 PI protection type to be overridden from userland.

Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/sd.c

index 1a903b09496a26a26ca35110558d90fa94aa50f5..ba5b9147c628fbb89331fedaa624ff1856b4a92b 100644 (file)
@@ -258,6 +258,24 @@ sd_show_protection_type(struct device *dev, struct device_attribute *attr,
        return snprintf(buf, 20, "%u\n", sdkp->protection_type);
 }
 
+static ssize_t
+sd_store_protection_type(struct device *dev, struct device_attribute *attr,
+                        const char *buf, size_t count)
+{
+       struct scsi_disk *sdkp = to_scsi_disk(dev);
+       unsigned long val;
+
+       if (!capable(CAP_SYS_ADMIN))
+               return -EACCES;
+
+       val = simple_strtoul(buf, NULL, 10);
+
+       if (val >= 0 && val <= SD_DIF_TYPE3_PROTECTION)
+               sdkp->protection_type = val;
+
+       return count;
+}
+
 static ssize_t
 sd_show_protection_mode(struct device *dev, struct device_attribute *attr,
                        char *buf)
@@ -353,7 +371,8 @@ static struct device_attribute sd_disk_attrs[] = {
               sd_store_allow_restart),
        __ATTR(manage_start_stop, S_IRUGO|S_IWUSR, sd_show_manage_start_stop,
               sd_store_manage_start_stop),
-       __ATTR(protection_type, S_IRUGO, sd_show_protection_type, NULL),
+       __ATTR(protection_type, S_IRUGO|S_IWUSR, sd_show_protection_type,
+              sd_store_protection_type),
        __ATTR(protection_mode, S_IRUGO, sd_show_protection_mode, NULL),
        __ATTR(app_tag_own, S_IRUGO, sd_show_app_tag_own, NULL),
        __ATTR(thin_provisioning, S_IRUGO, sd_show_thin_provisioning, NULL),