diff options
author | Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> | 2024-10-07 11:45:46 +0200 |
---|---|---|
committer | Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com> | 2024-11-04 10:25:26 +0100 |
commit | fdeb831823b63d1ee6c95a892af201b1550e6ee5 (patch) | |
tree | 892c8a09cd4345b6523e2b78d94408afbde385be /sysfs.c | |
parent | [PATCH] mdadm: Grow.c distinguish takeover vs reshape on grow operation (diff) | |
download | mdadm-fdeb831823b63d1ee6c95a892af201b1550e6ee5.tar.xz mdadm-fdeb831823b63d1ee6c95a892af201b1550e6ee5.zip |
sysfs: add sysfs_open_memb_attr()
Function is added to not repeat defining "dev-%s", disk_name.
Related code branches are updated. Ioctl way for setting disk
faulty/remove is removed, sysfs is always used now.
Some non functional style issues are fixed in Manage_subdevs().
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Diffstat (limited to 'sysfs.c')
-rw-r--r-- | sysfs.c | 23 |
1 files changed, 21 insertions, 2 deletions
@@ -140,6 +140,24 @@ void sysfs_get_container_devnm(struct mdinfo *mdi, char *buf) *p = 0; } +/** + * sysfs_open_memb_attr() - helper to get sysfs attr descriptor for member device. + * @array_devnm: array kernel device name. + * @memb_devnm: member device kernel device name. + * @attr: requested sysfs attribute. + * @oflag: open() flags. + * + * To refer member device directory, we need to append "dev-" before the member device name. + */ +int sysfs_open_memb_attr(char *array_devnm, char *memb_devnm, char *attr, int oflag) +{ + char path[PATH_MAX]; + + snprintf(path, PATH_MAX, "/sys/block/%s/md/dev-%s/%s", array_devnm, memb_devnm, attr); + + return open(path, oflag); +} + int sysfs_open(char *devnm, char *devname, char *attr) { char fname[MAX_SYSFS_PATH_LEN]; @@ -189,6 +207,7 @@ out: return retval; } +/* If fd >= 0, get the array it is open on, else use devnm. */ struct mdinfo *sysfs_read(int fd, char *devnm, unsigned long options) { char fname[PATH_MAX]; @@ -817,8 +836,8 @@ int sysfs_add_disk(struct mdinfo *sra, struct mdinfo *sd, int resume) memset(nm, 0, sizeof(nm)); dname = devid2kname(makedev(sd->disk.major, sd->disk.minor)); - strcpy(sd->sys_name, "dev-"); - strcpy(sd->sys_name+4, dname); + + snprintf(sd->sys_name, sizeof(sd->sys_name), "dev-%s", dname); /* test write to see if 'recovery_start' is available */ if (resume && sd->recovery_start < MaxSector && |