core/umount: replace udev_device by sd_device

This commit is contained in:
Yu Watanabe 2018-08-22 14:39:12 +09:00
parent 21384b8129
commit 6bcf00eda3

View file

@ -13,11 +13,12 @@
/* This needs to be after sys/mount.h :( */ /* This needs to be after sys/mount.h :( */
#include <libmount.h> #include <libmount.h>
#include "libudev.h" #include "sd-device.h"
#include "alloc-util.h" #include "alloc-util.h"
#include "blockdev-util.h" #include "blockdev-util.h"
#include "def.h" #include "def.h"
#include "device-enumerator-private.h"
#include "escape.h" #include "escape.h"
#include "fd-util.h" #include "fd-util.h"
#include "fstab-util.h" #include "fstab-util.h"
@ -28,7 +29,6 @@
#include "process-util.h" #include "process-util.h"
#include "signal-util.h" #include "signal-util.h"
#include "string-util.h" #include "string-util.h"
#include "udev-util.h"
#include "umount.h" #include "umount.h"
#include "util.h" #include "util.h"
#include "virt.h" #include "virt.h"
@ -229,49 +229,41 @@ int swap_list_get(const char *swaps, MountPoint **head) {
} }
static int loopback_list_get(MountPoint **head) { static int loopback_list_get(MountPoint **head) {
_cleanup_(udev_enumerate_unrefp) struct udev_enumerate *e = NULL; _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
struct udev_list_entry *item = NULL, *first = NULL; sd_device *d;
_cleanup_(udev_unrefp) struct udev *udev = NULL;
int r; int r;
assert(head); assert(head);
udev = udev_new(); r = sd_device_enumerator_new(&e);
if (!udev)
return -ENOMEM;
e = udev_enumerate_new(udev);
if (!e)
return -ENOMEM;
r = udev_enumerate_add_match_subsystem(e, "block");
if (r < 0) if (r < 0)
return r; return r;
r = udev_enumerate_add_match_sysname(e, "loop*"); r = sd_device_enumerator_allow_uninitialized(e);
if (r < 0) if (r < 0)
return r; return r;
r = udev_enumerate_add_match_sysattr(e, "loop/backing_file", NULL); r = sd_device_enumerator_add_match_subsystem(e, "block", true);
if (r < 0) if (r < 0)
return r; return r;
r = udev_enumerate_scan_devices(e); r = sd_device_enumerator_add_match_sysname(e, "loop*");
if (r < 0) if (r < 0)
return r; return r;
first = udev_enumerate_get_list_entry(e); r = sd_device_enumerator_add_match_sysattr(e, "loop/backing_file", NULL, true);
udev_list_entry_foreach(item, first) { if (r < 0)
_cleanup_(udev_device_unrefp) struct udev_device *d; return r;
const char *dn;
r = device_enumerator_scan_devices(e);
if (r < 0)
return r;
FOREACH_DEVICE_AND_SUBSYSTEM(e, d) {
_cleanup_free_ MountPoint *lb = NULL; _cleanup_free_ MountPoint *lb = NULL;
const char *dn;
d = udev_device_new_from_syspath(udev, udev_list_entry_get_name(item)); if (sd_device_get_devname(d, &dn) < 0)
if (!d)
return -ENOMEM;
dn = udev_device_get_devnode(d);
if (!dn)
continue; continue;
lb = new0(MountPoint, 1); lb = new0(MountPoint, 1);
@ -290,47 +282,41 @@ static int loopback_list_get(MountPoint **head) {
} }
static int dm_list_get(MountPoint **head) { static int dm_list_get(MountPoint **head) {
_cleanup_(udev_enumerate_unrefp) struct udev_enumerate *e = NULL; _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
struct udev_list_entry *item = NULL, *first = NULL; sd_device *d;
_cleanup_(udev_unrefp) struct udev *udev = NULL;
int r; int r;
assert(head); assert(head);
udev = udev_new(); r = sd_device_enumerator_new(&e);
if (!udev)
return -ENOMEM;
e = udev_enumerate_new(udev);
if (!e)
return -ENOMEM;
r = udev_enumerate_add_match_subsystem(e, "block");
if (r < 0) if (r < 0)
return r; return r;
r = udev_enumerate_add_match_sysname(e, "dm-*"); r = sd_device_enumerator_allow_uninitialized(e);
if (r < 0) if (r < 0)
return r; return r;
r = udev_enumerate_scan_devices(e); r = sd_device_enumerator_add_match_subsystem(e, "block", true);
if (r < 0) if (r < 0)
return r; return r;
first = udev_enumerate_get_list_entry(e); r = sd_device_enumerator_add_match_sysname(e, "dm-*");
udev_list_entry_foreach(item, first) { if (r < 0)
_cleanup_(udev_device_unrefp) struct udev_device *d; return r;
dev_t devnum;
const char *dn; r = device_enumerator_scan_devices(e);
if (r < 0)
return r;
FOREACH_DEVICE_AND_SUBSYSTEM(e, d) {
_cleanup_free_ MountPoint *m = NULL; _cleanup_free_ MountPoint *m = NULL;
const char *dn;
dev_t devnum;
d = udev_device_new_from_syspath(udev, udev_list_entry_get_name(item)); if (sd_device_get_devnum(d, &devnum) < 0)
if (!d) continue;
return -ENOMEM;
devnum = udev_device_get_devnum(d); if (sd_device_get_devname(d, &dn) < 0)
dn = udev_device_get_devnode(d);
if (major(devnum) == 0 || !dn)
continue; continue;
m = new0(MountPoint, 1); m = new0(MountPoint, 1);