file-posix: introduce get_sysfs_long_val for the long sysfs attribute
RFC v5 3/11 file-posix: introduce get_sysfs_long_val for the long sysfs attribute
Use sysfs attribute files to get the long value of zoned device information.
Signed-off-by Sam Li <[email protected]>
--- block/file-posix.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-)
block/file-posix.c +16 -7
@@ -1210,15 +1210,19 @@ static int hdev_get_max_hw_transfer(int fd, struct stat *st)#endif } -static int hdev_get_max_segments (int fd,struct stat *st) -{ +/* +* Get zoned device information (chunk_sectors, zoned_append_max_bytes, +* max_open_zones, max_active_zones) through sysfs attribute files. +*/ +static long get_sysfs_long_val (int fd,struct stat *st, +const char *attribute) {#ifdef CONFIG_LINUX char buf[32 ];const char *end;char *sysfspath =NULL ;int ret;int sysfd =-1 ; -long max_segments; +long val;if (S_ISCHR (st->st_mode)) {if (ioctl (fd,SG_GET_SG_TABLESIZE , &ret) ==0 ) {
@@ -1231,8 +1235,9 @@ static int hdev_get_max_segments(int fd, struct stat *st)return -ENOTSUP ; } - sysfspath =g_strdup_printf ("/sys/dev/block/%u:%u/queue/max_segments" , -major (st->st_rdev),minor (st->st_rdev)); + sysfspath =g_strdup_printf ("/sys/dev/block/%u:%u/queue/%s" , +major (st->st_rdev),minor (st->st_rdev), + attribute); sysfd =open (sysfspath,O_RDONLY );if (sysfd ==-1 ) { ret = -errno;
@@ -1250,9 +1255,9 @@ static int hdev_get_max_segments(int fd, struct stat *st) } buf[ret] =0 ;/* The file is ended with '\n', pass 'end' to accept that. */ - ret =qemu_strtol (buf, &end,10 , &max_segments); + ret =qemu_strtol (buf, &end,10 , &val);if (ret ==0 && end && *end =='\n' ) { - ret = max_segments; + ret = val; } out:
@@ -1266,6 +1271,10 @@ out:#endif } +static int hdev_get_max_segments (int fd,struct stat *st) { +return get_sysfs_long_val (fd, st,"max_segments" ); +} +static void raw_refresh_limits (BlockDriverState *bs,Error **errp) {BDRVRawState *s = bs->opaque;
Signature · 1 line
2.37.1
Quoted 26 lines · Sam Li
Use sysfs attribute files to get the long value of zoned device information.
Signed-off-by Sam Li <[email protected]>--- block/file-posix.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-)block/file-posix.c +6
-2@@ -1210,15 +1210,19 @@ static int hdev_get_max_hw_transfer(int fd, struct stat *st)#endif } -static int hdev_get_max_segments (int fd,struct stat *st) -{ +/* +* Get zoned device information (chunk_sectors, zoned_append_max_bytes, +* max_open_zones, max_active_zones) through sysfs attribute files. +*/ +static long get_sysfs_long_val (int fd,struct stat *st, +const char *attribute) {#ifdef CONFIG_LINUX
block/file-posix.c static int hdev_get_max_hw_transfer(int fd, struct stat *st) · line 1228
Quoted 10 lines
block/file-posix.c +1
-1char buf[32 ];const char *end;char *sysfspath =NULL ;int ret;int sysfd =-1 ; -long max_segments; +long val;if (S_ISCHR (st->st_mode)) {if (ioctl (fd,SG_GET_SG_TABLESIZE , &ret) ==0 ) {
This code is specific to max_segments and not relevant to other attributes. It's an alternative code path for SCSI generic types of devices. It should be moved into hdev_get_max_segments() before get_sysfs_long_val() is called.
Quoted 39 lines
block/file-posix.c +9
-5@@ -1231,8 +1235,9 @@ static int hdev_get_max_segments(int fd, struct stat *st)return -ENOTSUP ; } - sysfspath =g_strdup_printf ("/sys/dev/block/%u:%u/queue/max_segments" , -major (st->st_rdev),minor (st->st_rdev)); + sysfspath =g_strdup_printf ("/sys/dev/block/%u:%u/queue/%s" , +major (st->st_rdev),minor (st->st_rdev), + attribute); sysfd =open (sysfspath,O_RDONLY );if (sysfd ==-1 ) { ret = -errno;@@ -1250,9 +1255,9 @@ static int hdev_get_max_segments(int fd, struct stat *st) } buf[ret] =0 ;/* The file is ended with '\n', pass 'end' to accept that. */ - ret =qemu_strtol (buf, &end,10 , &max_segments); + ret =qemu_strtol (buf, &end,10 , &val);if (ret ==0 && end && *end =='\n' ) { - ret = max_segments; + ret = val; } out:@@ -1266,6 +1271,10 @@ out:#endif } +static int hdev_get_max_segments (int fd,struct stat *st) { +return get_sysfs_long_val (fd, st,"max_segments" ); +} +static void raw_refresh_limits (BlockDriverState *bs,Error **errp) {BDRVRawState *s = bs->opaque; --2.37.1