summaryrefslogtreecommitdiff
path: root/src/partition/growfs.c
diff options
context:
space:
mode:
authorDevendra Tewari <devendra.tewari@gmail.com>2022-08-26 08:32:48 -0300
committerLuca Boccassi <luca.boccassi@gmail.com>2022-08-26 20:33:03 +0100
commit0f79b3469f167583033d17f9a6fa0e4341a68003 (patch)
treeb5867d74efcb98efecd51ef4735a825a3b246043 /src/partition/growfs.c
parent528ba54bbe3cf6c454985952d49e7a49ba62e244 (diff)
downloadsystemd-0f79b3469f167583033d17f9a6fa0e4341a68003.tar.gz
systemd-growfs: use sd_device_new_from_devnum()
Use sd_device_new_from_devnum() instead of device_path_make_major_minor_sysfs().
Diffstat (limited to 'src/partition/growfs.c')
-rw-r--r--src/partition/growfs.c64
1 files changed, 46 insertions, 18 deletions
diff --git a/src/partition/growfs.c b/src/partition/growfs.c
index e940dccd48..88e503c86d 100644
--- a/src/partition/growfs.c
+++ b/src/partition/growfs.c
@@ -10,10 +10,13 @@
#include <sys/types.h>
#include <sys/vfs.h>
+#include "sd-device.h"
+
#include "blockdev-util.h"
#include "btrfs-util.h"
#include "cryptsetup-util.h"
#include "device-nodes.h"
+#include "device-util.h"
#include "devnum-util.h"
#include "dissect-image.h"
#include "escape.h"
@@ -31,7 +34,8 @@ static bool arg_dry_run = false;
#if HAVE_LIBCRYPTSETUP
static int resize_crypt_luks_device(dev_t devno, const char *fstype, dev_t main_devno) {
- _cleanup_free_ char *devpath = NULL, *main_devpath = NULL;
+ _cleanup_(sd_device_unrefp) sd_device *main_dev = NULL, *dev = NULL;
+ const char *devpath, *main_devpath;
_cleanup_(sym_crypt_freep) struct crypt_device *cd = NULL;
_cleanup_close_ int main_devfd = -1;
uint64_t size;
@@ -41,22 +45,33 @@ static int resize_crypt_luks_device(dev_t devno, const char *fstype, dev_t main_
if (r < 0)
return log_error_errno(r, "Cannot resize LUKS device: %m");
- r = device_path_make_major_minor_sysfs(S_IFBLK, main_devno, &main_devpath);
+ r = sd_device_new_from_devnum(&main_dev, 'b', main_devno);
+ if (r < 0)
+ return log_error_errno(r, "Failed to create main sd-device for block device " DEVNUM_FORMAT_STR ": %m",
+ DEVNUM_FORMAT_VAL(main_devno));
+
+ r = sd_device_get_devpath(main_dev, &main_devpath);
if (r < 0)
- return log_error_errno(r, "Failed to format device major/minor path: %m");
+ return log_device_error_errno(main_dev, r, "Failed to get main devpath: %m");
- main_devfd = open(main_devpath, O_RDONLY|O_CLOEXEC);
+ main_devfd = sd_device_open(main_dev, O_RDONLY|O_CLOEXEC);
if (main_devfd < 0)
- return log_error_errno(errno, "Failed to open \"%s\": %m", main_devpath);
+ return log_device_error_errno(main_dev, main_devfd, "Failed to open block device \"%s\": %m",
+ main_devpath);
if (ioctl(main_devfd, BLKGETSIZE64, &size) != 0)
return log_error_errno(errno, "Failed to query size of \"%s\" (before resize): %m",
main_devpath);
log_debug("%s is %"PRIu64" bytes", main_devpath, size);
- r = device_path_make_major_minor_sysfs(S_IFBLK, devno, &devpath);
+ r = sd_device_new_from_devnum(&dev, 'b', devno);
+ if (r < 0)
+ return log_error_errno(r, "Failed to create sd-device for block device " DEVNUM_FORMAT_STR ": %m",
+ DEVNUM_FORMAT_VAL(devno));
+
+ r = sd_device_get_devpath(dev, &devpath);
if (r < 0)
- return log_error_errno(r, "Failed to format major/minor path: %m");
+ return log_device_error_errno(dev, r, "Failed to get devpath: %m");
r = sym_crypt_init(&cd, devpath);
if (r < 0)
@@ -90,7 +105,9 @@ static int maybe_resize_underlying_device(
const char *mountpath,
dev_t main_devno) {
- _cleanup_free_ char *fstype = NULL, *devpath = NULL;
+ _cleanup_(sd_device_unrefp) sd_device *dev = NULL;
+ _cleanup_free_ char *fstype = NULL;
+ const char *devpath;
dev_t devno;
int r;
@@ -108,16 +125,21 @@ static int maybe_resize_underlying_device(
if (devno == 0)
return log_error_errno(SYNTHETIC_ERRNO(ENODEV), "File system \"%s\" not backed by block device.", arg_target);
- log_debug("Underlying device %d:%d, main dev %d:%d, %s",
- major(devno), minor(devno),
- major(main_devno), minor(main_devno),
+ log_debug("Underlying device " DEVNUM_FORMAT_STR ", main dev " DEVNUM_FORMAT_STR ", %s",
+ DEVNUM_FORMAT_VAL(devno),
+ DEVNUM_FORMAT_VAL(main_devno),
devno == main_devno ? "same" : "different");
if (devno == main_devno)
return 0;
- r = device_path_make_major_minor_sysfs(S_IFBLK, devno, &devpath);
+ r = sd_device_new_from_devnum(&dev, 'b', devno);
if (r < 0)
- return log_error_errno(r, "Failed to format device major/minor path: %m");
+ return log_error_errno(r, "Failed to create sd-device for block device " DEVNUM_FORMAT_STR ": %m",
+ DEVNUM_FORMAT_VAL(devno));
+
+ r = sd_device_get_devpath(dev, &devpath);
+ if (r < 0)
+ return log_device_error_errno(dev, r, "Failed to get devpath: %m");
r = probe_filesystem(devpath, &fstype);
if (r == -EUCLEAN)
@@ -202,8 +224,9 @@ static int parse_argv(int argc, char *argv[]) {
}
static int run(int argc, char *argv[]) {
+ _cleanup_(sd_device_unrefp) sd_device *dev = NULL;
_cleanup_close_ int mountfd = -1, devfd = -1;
- _cleanup_free_ char *devpath = NULL;
+ const char *devpath;
uint64_t size, newsize;
struct stat st;
dev_t devno;
@@ -237,13 +260,18 @@ static int run(int argc, char *argv[]) {
if (r < 0)
log_warning_errno(r, "Unable to resize underlying device of \"%s\", proceeding anyway: %m", arg_target);
- r = device_path_make_major_minor_sysfs(S_IFBLK, devno, &devpath);
+ r = sd_device_new_from_devnum(&dev, 'b', devno);
+ if (r < 0)
+ return log_error_errno(r, "Failed to create sd-device for block device " DEVNUM_FORMAT_STR ": %m",
+ DEVNUM_FORMAT_VAL(devno));
+
+ r = sd_device_get_devpath(dev, &devpath);
if (r < 0)
- return log_error_errno(r, "Failed to format device major/minor path: %m");
+ return log_device_error_errno(dev, r, "Failed to get devpath: %m");
- devfd = open(devpath, O_RDONLY|O_CLOEXEC|O_NOCTTY);
+ devfd = sd_device_open(dev, O_RDONLY|O_CLOEXEC);
if (devfd < 0)
- return log_error_errno(errno, "Failed to open \"%s\": %m", devpath);
+ return log_device_error_errno(dev, devfd, "Failed to open block device \"%s\": %m", devpath);
if (fstat(devfd, &st) < 0)
return log_error_errno(r, "Failed to stat() device %s: %m", devpath);