summaryrefslogtreecommitdiffstats
path: root/block/blk-integrity.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2024-06-13 10:48:17 +0200
committerJens Axboe <axboe@kernel.dk>2024-06-14 18:20:06 +0200
commit1366251a794b149a132ef8423c8946b6e565a923 (patch)
tree87071805d072742770a7d66e15e3172161bf0542 /block/blk-integrity.c
parentblock: remove the blk_flush_integrity call in blk_integrity_unregister (diff)
downloadlinux-1366251a794b149a132ef8423c8946b6e565a923.tar.xz
linux-1366251a794b149a132ef8423c8946b6e565a923.zip
block: factor out flag_{store,show} helper for integrity
Factor the duplicate code for the generate and verify attributes into common helpers. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Keith Busch <kbusch@kernel.org> Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> Reviewed-by: Hannes Reinecke <hare@suse.de> Link: https://lore.kernel.org/r/20240613084839.1044015-8-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to '')
-rw-r--r--block/blk-integrity.c53
1 files changed, 26 insertions, 27 deletions
diff --git a/block/blk-integrity.c b/block/blk-integrity.c
index 24f04575096d..24671d9f90a1 100644
--- a/block/blk-integrity.c
+++ b/block/blk-integrity.c
@@ -243,6 +243,28 @@ const char *blk_integrity_profile_name(struct blk_integrity *bi)
}
EXPORT_SYMBOL_GPL(blk_integrity_profile_name);
+static ssize_t flag_store(struct device *dev, struct device_attribute *attr,
+ const char *page, size_t count, unsigned char flag)
+{
+ struct blk_integrity *bi = dev_to_bi(dev);
+ char *p = (char *) page;
+ unsigned long val = simple_strtoul(p, &p, 10);
+
+ if (val)
+ bi->flags |= flag;
+ else
+ bi->flags &= ~flag;
+ return count;
+}
+
+static ssize_t flag_show(struct device *dev, struct device_attribute *attr,
+ char *page, unsigned char flag)
+{
+ struct blk_integrity *bi = dev_to_bi(dev);
+
+ return sysfs_emit(page, "%d\n", !!(bi->flags & flag));
+}
+
static ssize_t format_show(struct device *dev, struct device_attribute *attr,
char *page)
{
@@ -275,49 +297,26 @@ static ssize_t read_verify_store(struct device *dev,
struct device_attribute *attr,
const char *page, size_t count)
{
- struct blk_integrity *bi = dev_to_bi(dev);
- char *p = (char *) page;
- unsigned long val = simple_strtoul(p, &p, 10);
-
- if (val)
- bi->flags |= BLK_INTEGRITY_VERIFY;
- else
- bi->flags &= ~BLK_INTEGRITY_VERIFY;
-
- return count;
+ return flag_store(dev, attr, page, count, BLK_INTEGRITY_VERIFY);
}
static ssize_t read_verify_show(struct device *dev,
struct device_attribute *attr, char *page)
{
- struct blk_integrity *bi = dev_to_bi(dev);
-
- return sysfs_emit(page, "%d\n", !!(bi->flags & BLK_INTEGRITY_VERIFY));
+ return flag_show(dev, attr, page, BLK_INTEGRITY_VERIFY);
}
static ssize_t write_generate_store(struct device *dev,
struct device_attribute *attr,
const char *page, size_t count)
{
- struct blk_integrity *bi = dev_to_bi(dev);
-
- char *p = (char *) page;
- unsigned long val = simple_strtoul(p, &p, 10);
-
- if (val)
- bi->flags |= BLK_INTEGRITY_GENERATE;
- else
- bi->flags &= ~BLK_INTEGRITY_GENERATE;
-
- return count;
+ return flag_store(dev, attr, page, count, BLK_INTEGRITY_GENERATE);
}
static ssize_t write_generate_show(struct device *dev,
struct device_attribute *attr, char *page)
{
- struct blk_integrity *bi = dev_to_bi(dev);
-
- return sysfs_emit(page, "%d\n", !!(bi->flags & BLK_INTEGRITY_GENERATE));
+ return flag_show(dev, attr, page, BLK_INTEGRITY_GENERATE);
}
static ssize_t device_is_integrity_capable_show(struct device *dev,