mirror of
https://github.com/systemd/systemd.git
synced 2024-11-27 04:03:36 +08:00
sd-device: rename devpath_from_devnum() -> devname_from_devnum()
In sd-device, `devpath` is a kind of syspath without '/sys' prefix, e.g. /devices/pci0000:00/0000:00:1c.4/0000:3c:00.0/nvme/nvme0/nvme0n1, and `devname` is a path to the device node, e.g. /dev/nvme0n1. Let's use the consistent name for the helper function.
This commit is contained in:
parent
81e327c42c
commit
4fe46c349d
@ -304,7 +304,7 @@ static int swap_load_devnode(Swap *s) {
|
||||
if (stat(s->what, &st) < 0 || !S_ISBLK(st.st_mode))
|
||||
return 0;
|
||||
|
||||
r = devpath_from_devnum(S_IFBLK, st.st_rdev, &p);
|
||||
r = devname_from_devnum(S_IFBLK, st.st_rdev, &p);
|
||||
if (r < 0) {
|
||||
log_unit_full_errno(UNIT(s), r == -ENOENT ? LOG_DEBUG : LOG_WARNING, r,
|
||||
"Failed to get device node for swap %s: %m", s->what);
|
||||
|
@ -880,7 +880,7 @@ static int action_umount(const char *path) {
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to find backing block device for '%s': %m", canonical);
|
||||
|
||||
r = devpath_from_devnum(S_IFBLK, devno, &devname);
|
||||
r = devname_from_devnum(S_IFBLK, devno, &devname);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to get devname of block device " DEVNUM_FORMAT_STR ": %m",
|
||||
DEVNUM_FORMAT_VAL(devno));
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include "fd-util.h"
|
||||
#include "string-util.h"
|
||||
|
||||
int devpath_from_devnum(mode_t mode, dev_t devnum, char **ret) {
|
||||
int devname_from_devnum(mode_t mode, dev_t devnum, char **ret) {
|
||||
_cleanup_(sd_device_unrefp) sd_device *dev = NULL;
|
||||
_cleanup_free_ char *s = NULL;
|
||||
const char *devname;
|
||||
|
@ -81,5 +81,5 @@
|
||||
#define log_device_warning_errno(device, error, ...) log_device_full_errno(device, LOG_WARNING, error, __VA_ARGS__)
|
||||
#define log_device_error_errno(device, error, ...) log_device_full_errno(device, LOG_ERR, error, __VA_ARGS__)
|
||||
|
||||
int devpath_from_devnum(mode_t mode, dev_t devnum, char **ret);
|
||||
int devname_from_devnum(mode_t mode, dev_t devnum, char **ret);
|
||||
int device_open_from_devnum(mode_t mode, dev_t devnum, int flags, char **ret);
|
||||
|
@ -500,7 +500,7 @@ TEST(sd_device_new_from_path) {
|
||||
}
|
||||
}
|
||||
|
||||
static void test_devpath_from_devnum_one(const char *path) {
|
||||
static void test_devname_from_devnum_one(const char *path) {
|
||||
_cleanup_free_ char *resolved = NULL;
|
||||
struct stat st;
|
||||
|
||||
@ -512,21 +512,21 @@ static void test_devpath_from_devnum_one(const char *path) {
|
||||
return;
|
||||
}
|
||||
|
||||
assert_se(devpath_from_devnum(st.st_mode, st.st_rdev, &resolved) >= 0);
|
||||
assert_se(devname_from_devnum(st.st_mode, st.st_rdev, &resolved) >= 0);
|
||||
assert_se(path_equal(path, resolved));
|
||||
}
|
||||
|
||||
TEST(devpath_from_devnum) {
|
||||
test_devpath_from_devnum_one("/dev/null");
|
||||
test_devpath_from_devnum_one("/dev/zero");
|
||||
test_devpath_from_devnum_one("/dev/full");
|
||||
test_devpath_from_devnum_one("/dev/random");
|
||||
test_devpath_from_devnum_one("/dev/urandom");
|
||||
test_devpath_from_devnum_one("/dev/tty");
|
||||
TEST(devname_from_devnum) {
|
||||
test_devname_from_devnum_one("/dev/null");
|
||||
test_devname_from_devnum_one("/dev/zero");
|
||||
test_devname_from_devnum_one("/dev/full");
|
||||
test_devname_from_devnum_one("/dev/random");
|
||||
test_devname_from_devnum_one("/dev/urandom");
|
||||
test_devname_from_devnum_one("/dev/tty");
|
||||
|
||||
if (is_device_node("/run/systemd/inaccessible/blk") > 0) {
|
||||
test_devpath_from_devnum_one("/run/systemd/inaccessible/chr");
|
||||
test_devpath_from_devnum_one("/run/systemd/inaccessible/blk");
|
||||
test_devname_from_devnum_one("/run/systemd/inaccessible/chr");
|
||||
test_devname_from_devnum_one("/run/systemd/inaccessible/blk");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -900,7 +900,7 @@ static int oci_devices(const char *name, JsonVariant *v, JsonDispatchFlags flags
|
||||
}
|
||||
|
||||
/* Suppress a couple of implicit device nodes */
|
||||
r = devpath_from_devnum(node->mode, makedev(node->major, node->minor), &path);
|
||||
r = devname_from_devnum(node->mode, makedev(node->major, node->minor), &path);
|
||||
if (r < 0)
|
||||
json_log(e, flags|JSON_DEBUG, 0, "Failed to resolve device node %u:%u, ignoring: %m", node->major, node->minor);
|
||||
else {
|
||||
|
@ -55,7 +55,7 @@ static int resize_crypt_luks_device(dev_t devno, const char *fstype, dev_t main_
|
||||
|
||||
log_debug("%s is %"PRIu64" bytes", main_devpath, size);
|
||||
|
||||
r = devpath_from_devnum(S_IFBLK, devno, &devpath);
|
||||
r = devname_from_devnum(S_IFBLK, devno, &devpath);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to get devpath of " DEVNUM_FORMAT_STR ": %m",
|
||||
DEVNUM_FORMAT_VAL(devno));
|
||||
@ -117,7 +117,7 @@ static int maybe_resize_underlying_device(
|
||||
if (devno == main_devno)
|
||||
return 0;
|
||||
|
||||
r = devpath_from_devnum(S_IFBLK, devno, &devpath);
|
||||
r = devname_from_devnum(S_IFBLK, devno, &devpath);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to get devpath for block device " DEVNUM_FORMAT_STR ": %m",
|
||||
DEVNUM_FORMAT_VAL(devno));
|
||||
|
@ -4508,7 +4508,7 @@ static int acquire_root_devno(
|
||||
if (r < 0)
|
||||
log_debug_errno(r, "Failed to find whole disk block device for '%s', ignoring: %m", p);
|
||||
|
||||
r = devpath_from_devnum(S_IFBLK, devno, ret);
|
||||
r = devname_from_devnum(S_IFBLK, devno, ret);
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Failed to determine canonical path for '%s': %m", p);
|
||||
|
||||
|
@ -45,7 +45,7 @@ static int verify_esp_blkid(
|
||||
const char *v;
|
||||
int r;
|
||||
|
||||
r = devpath_from_devnum(S_IFBLK, devid, &node);
|
||||
r = devname_from_devnum(S_IFBLK, devid, &node);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to get device path for " DEVNUM_FORMAT_STR ": %m", DEVNUM_FORMAT_VAL(devid));
|
||||
|
||||
@ -508,7 +508,7 @@ static int verify_xbootldr_blkid(
|
||||
const char *type, *v;
|
||||
int r;
|
||||
|
||||
r = devpath_from_devnum(S_IFBLK, devid, &node);
|
||||
r = devname_from_devnum(S_IFBLK, devid, &node);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to get block device path for " DEVNUM_FORMAT_STR ": %m",
|
||||
DEVNUM_FORMAT_VAL(devid));
|
||||
|
@ -15,7 +15,7 @@ int quotactl_devnum(int cmd, dev_t devnum, int id, void *addr) {
|
||||
/* Like quotactl() but takes a dev_t instead of a path to a device node, and fixes caddr_t → void*,
|
||||
* like we should, today */
|
||||
|
||||
r = devpath_from_devnum(S_IFBLK, devnum, &devnode);
|
||||
r = devname_from_devnum(S_IFBLK, devnum, &devnode);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
@ -608,7 +608,7 @@ int resource_resolve_path(
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||
"File system is not placed on a partition block device, cannot determine whole block device backing root file system.");
|
||||
|
||||
r = devpath_from_devnum(S_IFBLK, d, &p);
|
||||
r = devname_from_devnum(S_IFBLK, d, &p);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
@ -321,7 +321,7 @@ int lock_main(int argc, char *argv[], void *userdata) {
|
||||
for (size_t i = 0; i < n_devnos; i++) {
|
||||
_cleanup_free_ char *node = NULL;
|
||||
|
||||
r = devpath_from_devnum(S_IFBLK, devnos[i], &node);
|
||||
r = devname_from_devnum(S_IFBLK, devnos[i], &node);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to format block device path: %m");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user