Add support for FS_IOC_GETFSSYSFSPATH

With single device mode we won't always show up in sysfs by UUID, but
the new VFS ioctl handles this nicely.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2025-04-13 18:39:23 -04:00
parent 844721635c
commit c9ee646718

View File

@ -16,6 +16,7 @@
#include <uuid/uuid.h>
#include <linux/fs.h>
#include <linux/mm.h>
#include "libbcachefs.h"
@ -447,12 +448,19 @@ int bcache_fs_open_fallible(const char *path, struct bchfs_handle *fs)
fs->uuid = uuid.uuid;
char uuid_str[40];
uuid_unparse(uuid.uuid.b, uuid_str);
struct fs_sysfs_path fs_sysfs_path;
if (!ioctl(path_fd, FS_IOC_GETFSSYSFSPATH, &fs_sysfs_path)) {
char *sysfs = mprintf("/sys/fs/%s", fs_sysfs_path.name);
fs->sysfs_fd = xopen(sysfs, O_RDONLY);
free(sysfs);
} else {
char uuid_str[40];
uuid_unparse(uuid.uuid.b, uuid_str);
char *sysfs = mprintf(SYSFS_BASE "%s", uuid_str);
fs->sysfs_fd = xopen(sysfs, O_RDONLY);
free(sysfs);
char *sysfs = mprintf(SYSFS_BASE "%s", uuid_str);
fs->sysfs_fd = xopen(sysfs, O_RDONLY);
free(sysfs);
}
return 0;
}