Commit 76b8c319 authored by Thomas Weißschuh's avatar Thomas Weißschuh Committed by Jens Axboe

blk-integrity: convert to struct device_attribute

An upcoming patch will register the integrity attributes directly with
the struct device kobject.
For this the attributes have to be implemented in terms of
struct device_attribute.
Signed-off-by: default avatarThomas Weißschuh <linux@weissschuh.net>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
Link: https://lore.kernel.org/r/20230309-kobj_release-gendisk_integrity-v3-2-ceccb4493c46@weissschuh.netSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 3315e169
...@@ -212,21 +212,15 @@ bool blk_integrity_merge_bio(struct request_queue *q, struct request *req, ...@@ -212,21 +212,15 @@ bool blk_integrity_merge_bio(struct request_queue *q, struct request *req,
return true; return true;
} }
struct integrity_sysfs_entry {
struct attribute attr;
ssize_t (*show)(struct blk_integrity *, char *);
ssize_t (*store)(struct blk_integrity *, const char *, size_t);
};
static ssize_t integrity_attr_show(struct kobject *kobj, struct attribute *attr, static ssize_t integrity_attr_show(struct kobject *kobj, struct attribute *attr,
char *page) char *page)
{ {
struct gendisk *disk = container_of(kobj, struct gendisk, integrity_kobj); struct gendisk *disk = container_of(kobj, struct gendisk, integrity_kobj);
struct blk_integrity *bi = &disk->queue->integrity; struct device *dev = disk_to_dev(disk);
struct integrity_sysfs_entry *entry = struct device_attribute *dev_attr =
container_of(attr, struct integrity_sysfs_entry, attr); container_of(attr, struct device_attribute, attr);
return entry->show(bi, page); return dev_attr->show(dev, dev_attr, page);
} }
static ssize_t integrity_attr_store(struct kobject *kobj, static ssize_t integrity_attr_store(struct kobject *kobj,
...@@ -234,38 +228,53 @@ static ssize_t integrity_attr_store(struct kobject *kobj, ...@@ -234,38 +228,53 @@ static ssize_t integrity_attr_store(struct kobject *kobj,
size_t count) size_t count)
{ {
struct gendisk *disk = container_of(kobj, struct gendisk, integrity_kobj); struct gendisk *disk = container_of(kobj, struct gendisk, integrity_kobj);
struct blk_integrity *bi = &disk->queue->integrity; struct device *dev = disk_to_dev(disk);
struct integrity_sysfs_entry *entry = struct device_attribute *dev_attr =
container_of(attr, struct integrity_sysfs_entry, attr); container_of(attr, struct device_attribute, attr);
ssize_t ret = 0;
if (entry->store) if (!dev_attr->store)
ret = entry->store(bi, page, count); return 0;
return dev_attr->store(dev, dev_attr, page, count);
}
return ret; static inline struct blk_integrity *dev_to_bi(struct device *dev)
{
return &dev_to_disk(dev)->queue->integrity;
} }
static ssize_t integrity_format_show(struct blk_integrity *bi, char *page) static ssize_t format_show(struct device *dev, struct device_attribute *attr,
char *page)
{ {
struct blk_integrity *bi = dev_to_bi(dev);
if (bi->profile && bi->profile->name) if (bi->profile && bi->profile->name)
return sysfs_emit(page, "%s\n", bi->profile->name); return sysfs_emit(page, "%s\n", bi->profile->name);
return sysfs_emit(page, "none\n"); return sysfs_emit(page, "none\n");
} }
static ssize_t integrity_tag_size_show(struct blk_integrity *bi, char *page) static ssize_t tag_size_show(struct device *dev, struct device_attribute *attr,
char *page)
{ {
struct blk_integrity *bi = dev_to_bi(dev);
return sysfs_emit(page, "%u\n", bi->tag_size); return sysfs_emit(page, "%u\n", bi->tag_size);
} }
static ssize_t integrity_interval_show(struct blk_integrity *bi, char *page) static ssize_t protection_interval_bytes_show(struct device *dev,
struct device_attribute *attr,
char *page)
{ {
struct blk_integrity *bi = dev_to_bi(dev);
return sysfs_emit(page, "%u\n", return sysfs_emit(page, "%u\n",
bi->interval_exp ? 1 << bi->interval_exp : 0); bi->interval_exp ? 1 << bi->interval_exp : 0);
} }
static ssize_t integrity_verify_store(struct blk_integrity *bi, static ssize_t read_verify_store(struct device *dev,
struct device_attribute *attr,
const char *page, size_t count) const char *page, size_t count)
{ {
struct blk_integrity *bi = dev_to_bi(dev);
char *p = (char *) page; char *p = (char *) page;
unsigned long val = simple_strtoul(p, &p, 10); unsigned long val = simple_strtoul(p, &p, 10);
...@@ -277,14 +286,20 @@ static ssize_t integrity_verify_store(struct blk_integrity *bi, ...@@ -277,14 +286,20 @@ static ssize_t integrity_verify_store(struct blk_integrity *bi,
return count; return count;
} }
static ssize_t integrity_verify_show(struct blk_integrity *bi, char *page) 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 sysfs_emit(page, "%d\n", !!(bi->flags & BLK_INTEGRITY_VERIFY));
} }
static ssize_t integrity_generate_store(struct blk_integrity *bi, static ssize_t write_generate_store(struct device *dev,
struct device_attribute *attr,
const char *page, size_t count) const char *page, size_t count)
{ {
struct blk_integrity *bi = dev_to_bi(dev);
char *p = (char *) page; char *p = (char *) page;
unsigned long val = simple_strtoul(p, &p, 10); unsigned long val = simple_strtoul(p, &p, 10);
...@@ -296,57 +311,39 @@ static ssize_t integrity_generate_store(struct blk_integrity *bi, ...@@ -296,57 +311,39 @@ static ssize_t integrity_generate_store(struct blk_integrity *bi,
return count; return count;
} }
static ssize_t integrity_generate_show(struct blk_integrity *bi, char *page) 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 sysfs_emit(page, "%d\n", !!(bi->flags & BLK_INTEGRITY_GENERATE));
} }
static ssize_t integrity_device_show(struct blk_integrity *bi, char *page) static ssize_t device_is_integrity_capable_show(struct device *dev,
struct device_attribute *attr,
char *page)
{ {
struct blk_integrity *bi = dev_to_bi(dev);
return sysfs_emit(page, "%u\n", return sysfs_emit(page, "%u\n",
!!(bi->flags & BLK_INTEGRITY_DEVICE_CAPABLE)); !!(bi->flags & BLK_INTEGRITY_DEVICE_CAPABLE));
} }
static struct integrity_sysfs_entry integrity_format_entry = { static DEVICE_ATTR_RO(format);
.attr = { .name = "format", .mode = 0444 }, static DEVICE_ATTR_RO(tag_size);
.show = integrity_format_show, static DEVICE_ATTR_RO(protection_interval_bytes);
}; static DEVICE_ATTR_RW(read_verify);
static DEVICE_ATTR_RW(write_generate);
static struct integrity_sysfs_entry integrity_tag_size_entry = { static DEVICE_ATTR_RO(device_is_integrity_capable);
.attr = { .name = "tag_size", .mode = 0444 },
.show = integrity_tag_size_show,
};
static struct integrity_sysfs_entry integrity_interval_entry = {
.attr = { .name = "protection_interval_bytes", .mode = 0444 },
.show = integrity_interval_show,
};
static struct integrity_sysfs_entry integrity_verify_entry = {
.attr = { .name = "read_verify", .mode = 0644 },
.show = integrity_verify_show,
.store = integrity_verify_store,
};
static struct integrity_sysfs_entry integrity_generate_entry = {
.attr = { .name = "write_generate", .mode = 0644 },
.show = integrity_generate_show,
.store = integrity_generate_store,
};
static struct integrity_sysfs_entry integrity_device_entry = {
.attr = { .name = "device_is_integrity_capable", .mode = 0444 },
.show = integrity_device_show,
};
static struct attribute *integrity_attrs[] = { static struct attribute *integrity_attrs[] = {
&integrity_format_entry.attr, &dev_attr_format.attr,
&integrity_tag_size_entry.attr, &dev_attr_tag_size.attr,
&integrity_interval_entry.attr, &dev_attr_protection_interval_bytes.attr,
&integrity_verify_entry.attr, &dev_attr_read_verify.attr,
&integrity_generate_entry.attr, &dev_attr_write_generate.attr,
&integrity_device_entry.attr, &dev_attr_device_is_integrity_capable.attr,
NULL, NULL
}; };
ATTRIBUTE_GROUPS(integrity); ATTRIBUTE_GROUPS(integrity);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment