Skip to content

Commit

Permalink
Introduce exp_obj serial
Browse files Browse the repository at this point in the history
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 <robert.baldyga@open-cas.com>
  • Loading branch information
robertbaldyga committed Oct 19, 2024
1 parent 7a3b067 commit 53e49b5
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions modules/cas_cache/exp_obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -476,13 +499,19 @@ 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;

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:
Expand Down

0 comments on commit 53e49b5

Please sign in to comment.