From 53e49b5566c4925a5b397d3d71e2a143b6aace7b Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Sat, 19 Oct 2024 20:59:54 +0200 Subject: [PATCH] Introduce exp_obj serial This is meant to be used by lvm2 to recognize which one of the stacked devices should be used (be it backend device, or one of the bottom levels in multi-level cache configuration). Signed-off-by: Robert Baldyga --- modules/cas_cache/exp_obj.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/modules/cas_cache/exp_obj.c b/modules/cas_cache/exp_obj.c index a265aa73b..854adb34b 100644 --- a/modules/cas_cache/exp_obj.c +++ b/modules/cas_cache/exp_obj.c @@ -388,6 +388,29 @@ static int _cas_exp_obj_check_path(const char *dev_name) return result; } +static ssize_t cas_exp_obj_attr_serial_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct gendisk *gd = dev_to_disk(dev); + struct cas_disk *dsk = gd->private_data; + struct cas_exp_obj *exp_obj = dsk->exp_obj; + + return sysfs_emit(buf, "opencas-%s", exp_obj->dev_name); +} + +static struct device_attribute cas_exp_obj_attr_serial = + __ATTR(serial, 0444, cas_exp_obj_attr_serial_show, NULL); + +static struct attribute *device_attrs[] = { + &cas_exp_obj_attr_serial.attr, + NULL, +}; + +static const struct attribute_group device_attr_group = { + .attrs = device_attrs, + .name = "device", +}; + int cas_exp_obj_create(struct cas_disk *dsk, const char *dev_name, struct module *owner, struct cas_exp_obj_ops *ops, void *priv) { @@ -476,6 +499,10 @@ int cas_exp_obj_create(struct cas_disk *dsk, const char *dev_name, if (cas_add_disk(gd)) goto error_add_disk; + result = sysfs_create_group(&disk_to_dev(gd)->kobj, &device_attr_group); + if (result) + goto error_sysfs; + result = bd_claim_by_disk(cas_disk_get_blkdev(dsk), dsk, gd); if (result) goto error_bd_claim; @@ -483,6 +510,8 @@ int cas_exp_obj_create(struct cas_disk *dsk, const char *dev_name, return 0; error_bd_claim: + sysfs_remove_group(&disk_to_dev(gd)->kobj, &device_attr_group); +error_sysfs: del_gendisk(dsk->exp_obj->gd); error_add_disk: error_set_geometry: