Skip to content

Commit

Permalink
Fixes to get bits running on Linux:
Browse files Browse the repository at this point in the history
1. Fix type in expression
2. Fix up vdev_name()
3. Add support for properties.vdev in SYSFS
  • Loading branch information
mmaybee authored and allanjude committed Mar 29, 2021
1 parent 9d9a513 commit 114eb45
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 18 deletions.
1 change: 1 addition & 0 deletions include/sys/zfs_sysfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ boolean_t zfs_mod_supported(const char *, const char *);
#endif

#define ZFS_SYSFS_POOL_PROPERTIES "properties.pool"
#define ZFS_SYSFS_VDEV_PROPERTIES "properties.vdev"
#define ZFS_SYSFS_DATASET_PROPERTIES "properties.dataset"
#define ZFS_SYSFS_KERNEL_FEATURES "features.kernel"
#define ZFS_SYSFS_POOL_FEATURES "features.pool"
Expand Down
3 changes: 2 additions & 1 deletion lib/libzfs/libzfs_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,8 @@ vdev_expand_proplist(zpool_handle_t *zhp, const char *vdevname,
propname = nvpair_name(elem);

/* Skip properties that are not user defined */
if ((prop = vdev_name_to_prop(propname)) != ZPROP_INVAL)
if ((prop = vdev_name_to_prop(propname)) !=
(vdev_prop_t)ZPROP_INVAL)
continue;

if (nvpair_value_nvlist(elem, &propval) != 0)
Expand Down
33 changes: 33 additions & 0 deletions module/os/linux/zfs/zfs_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ struct zfs_mod_kobj {
static zfs_mod_kobj_t kernel_features_kobj;
static zfs_mod_kobj_t pool_features_kobj;
static zfs_mod_kobj_t dataset_props_kobj;
static zfs_mod_kobj_t vdev_props_kobj;
static zfs_mod_kobj_t pool_props_kobj;

/*
Expand Down Expand Up @@ -333,6 +334,20 @@ dataset_property_show(struct kobject *kobj, struct attribute *attr, char *buf)
return (len);
}

static ssize_t
vdev_property_show(struct kobject *kobj, struct attribute *attr, char *buf)
{
vdev_prop_t prop = vdev_name_to_prop(kobject_name(kobj));
zprop_desc_t *prop_tbl = vdev_prop_get_table();
ssize_t len;

ASSERT3U(prop, <, VDEV_NUM_PROPS);

len = zprop_sysfs_show(attr->name, &prop_tbl[prop], buf, PAGE_SIZE);

return (len);
}

static ssize_t
pool_property_show(struct kobject *kobj, struct attribute *attr, char *buf)
{
Expand Down Expand Up @@ -577,6 +592,14 @@ zfs_sysfs_properties_init(zfs_mod_kobj_t *zfs_kobj, struct kobject *parent,
context.p2k_show_func = pool_property_show;
err = zfs_kobj_init(zfs_kobj, 0, ZPOOL_NUM_PROPS,
pool_property_show);
} else if (type == ZFS_TYPE_VDEV) {
name = ZFS_SYSFS_VDEV_PROPERTIES;
context.p2k_table = vdev_prop_get_table();
context.p2k_attr_count = ZPOOL_PROP_ATTR_COUNT;
context.p2k_parent = zfs_kobj;
context.p2k_show_func = vdev_property_show;
err = zfs_kobj_init(zfs_kobj, 0, VDEV_NUM_PROPS,
vdev_property_show);
} else {
name = ZFS_SYSFS_DATASET_PROPERTIES;
context.p2k_table = zfs_prop_get_table();
Expand Down Expand Up @@ -639,12 +662,22 @@ zfs_sysfs_init(void)
return;
}

err = zfs_sysfs_properties_init(&vdev_props_kobj, parent,
ZFS_TYPE_VDEV);
if (err) {
zfs_kobj_fini(&kernel_features_kobj);
zfs_kobj_fini(&pool_features_kobj);
zfs_kobj_fini(&pool_props_kobj);
return;
}

err = zfs_sysfs_properties_init(&dataset_props_kobj, parent,
ZFS_TYPE_FILESYSTEM);
if (err) {
zfs_kobj_fini(&kernel_features_kobj);
zfs_kobj_fini(&pool_features_kobj);
zfs_kobj_fini(&pool_props_kobj);
zfs_kobj_fini(&vdev_props_kobj);
return;
}
}
Expand Down
3 changes: 2 additions & 1 deletion module/zcommon/zprop_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ zfs_mod_supported_prop(const char *name, zfs_type_t type)
return (B_TRUE);
#else
return (zfs_mod_supported(type == ZFS_TYPE_POOL ?
ZFS_SYSFS_POOL_PROPERTIES : ZFS_SYSFS_DATASET_PROPERTIES, name));
ZFS_SYSFS_POOL_PROPERTIES : (type == ZFS_TYPE_VDEV ?
ZFS_SYSFS_VDEV_PROPERTIES : ZFS_SYSFS_DATASET_PROPERTIES), name));
#endif
}

Expand Down
29 changes: 13 additions & 16 deletions module/zfs/vdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -5346,26 +5346,19 @@ vdev_xlate_walk(vdev_t *vd, const range_seg64_t *logical_rs,
}

static char *
vdev_name(vdev_t *vd)
vdev_name(vdev_t *vd, char *buf, int buflen)
{
char *ret;

ret = vd->vdev_path;
if (ret == NULL) {
if (vd->vdev_path == NULL) {
if (strcmp(vd->vdev_ops->vdev_op_type, "root") == 0) {
ret = vd->vdev_spa->spa_name;
return (vd->vdev_spa->spa_name);
} else if (!vd->vdev_ops->vdev_op_leaf) {
char namestr[64] = { 0 };

snprintf((char *)&namestr,
sizeof (namestr), "%s-%llu",
snprintf(buf, buflen, "%s-%llu",
vd->vdev_ops->vdev_op_type,
(u_longlong_t)vd->vdev_id);
ret = (char *)&namestr;
return (buf);
}
}

return (ret);
return (vd->vdev_path);
}

/*
Expand Down Expand Up @@ -5633,6 +5626,8 @@ vdev_prop_get(vdev_t *vd, nvlist_t *innvl, nvlist_t *outnvl)
mutex_enter(&spa->spa_props_lock);

if (nvprops != NULL) {
char namebuf[64] = { 0 };

while ((elem = nvlist_next_nvpair(nvprops, elem)) != NULL) {
intval = 0;
strval = NULL;
Expand All @@ -5643,7 +5638,7 @@ vdev_prop_get(vdev_t *vd, nvlist_t *innvl, nvlist_t *outnvl)
switch (prop) {
/* Special Read-only Properties */
case VDEV_PROP_NAME:
strval = vdev_name(vd);
strval = vdev_name(vd, namebuf, 64);
if (strval == NULL)
continue;
vdev_prop_add_list(outnvl, propname, strval, 0,
Expand Down Expand Up @@ -5743,7 +5738,8 @@ vdev_prop_get(vdev_t *vd, nvlist_t *innvl, nvlist_t *outnvl)
continue;
case VDEV_PROP_PARENT:
if (vd->vdev_parent != NULL) {
strval = vdev_name(vd->vdev_parent);
strval = vdev_name(vd->vdev_parent,
namebuf, 64);
vdev_prop_add_list(outnvl, propname,
strval, 0, ZPROP_SRC_NONE);
}
Expand All @@ -5756,7 +5752,8 @@ vdev_prop_get(vdev_t *vd, nvlist_t *innvl, nvlist_t *outnvl)
i++) {
char *vname;

vname = vdev_name(vd->vdev_child[i]);
vname = vdev_name(vd->vdev_child[i],
namebuf, 64);
if (vname == NULL)
vname = "(unknown)";
if (strlen(strval) > 0)
Expand Down

0 comments on commit 114eb45

Please sign in to comment.