Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-15-SP2:GA
btrfsprogs
0003-btrfs-progs-Add-fallback-code-for-path-dev...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0003-btrfs-progs-Add-fallback-code-for-path-device-ignore.patch of Package btrfsprogs
From ce929c9ff222968b142c9ace91270f2df028d318 Mon Sep 17 00:00:00 2001 From: Nikolay Borisov <nborisov@suse.com> Date: Thu, 30 Sep 2021 15:06:34 +0300 Subject: [PATCH 3/3] btrfs-progs: Add fallback code for path device ignore for static build Since libudev doesn't provide a static version of the library for static build btrfs-progs will have to provide manual fallback. This change does this by parsing the udev database files hosted at /run/udev/data/. Under that directory every block device should have a file with the following name: bMAJ:MIN. So implement the bare minimum code necessary to parse this file and search for the presence of DM_MULTIPATH_DEVICE_PATH udev attribute. This could likely be racy since access to the udev database is done outside of libudev but that's the best that can be done when implementing this manually. Signed-off-by: Nikolay Borisov <nborisov@suse.com> --- utils.c | 54 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/utils.c b/utils.c index 710c566a0548..988aee5562cf 100644 --- a/utils.c +++ b/utils.c @@ -1973,23 +1973,54 @@ int group_profile_max_safe_loss(u64 flags) } } -#ifdef HAVE_LIBUDEV -static bool is_path_device(char *device_path) +#ifdef STATIC_BUILD +static bool is_path_device(dev_t device) +{ + FILE *file; + char *line = NULL; + size_t len = 0; + ssize_t nread; + bool ret = false; + int ret2; + char path[PATH_MAX]; + + ret2 = snprintf(path, 100, "/run/udev/data/b%u:%u", major(device), + minor(device)); + + if (ret2 < 0) + return false; + + file = fopen(path, "r"); + if (file == NULL) + return false; + + while ((nread = getline(&line, &len, file)) != -1) { + if (strstr(line, "DM_MULTIPATH_DEVICE_PATH=1")) { + ret = true; + break; + } + } + + if (line) + free(line); + + fclose(file); + + return ret; +} +#elif defined(HAVE_LIBUDEV) +static bool is_path_device(dev_t device) { struct udev *udev = NULL; struct udev_device *dev = NULL; - struct stat dev_stat; const char *val; bool ret = false; - if (stat(device_path, &dev_stat) < 0) - return false; - udev = udev_new(); if (!udev) goto out; - dev = udev_device_new_from_devnum(udev, 'b', dev_stat.st_rdev); + dev = udev_device_new_from_devnum(udev, 'b', device); if (!dev) goto out; @@ -2003,7 +2034,7 @@ static bool is_path_device(char *device_path) return ret; } #else -static bool is_path_device(char *device_path) +static bool is_path_device(dev_t device) { return false; } @@ -2032,13 +2063,18 @@ int btrfs_scan_devices(void) iter = blkid_dev_iterate_begin(cache); blkid_dev_set_search(iter, "TYPE", "btrfs"); while (blkid_dev_next(iter, &dev) == 0) { + struct stat dev_stat; + dev = blkid_verify(cache, dev); if (!dev) continue; /* if we are here its definitely a btrfs disk*/ strncpy_null(path, blkid_dev_devname(dev)); - if (is_path_device(path)) + if (stat(path, &dev_stat) < 0) + continue; + + if (is_path_device(dev_stat.st_rdev)) continue; fd = open(path, O_RDONLY); -- 2.25.1
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor