Merge pull request #10996 from poettering/oci-prep
Preparation for the nspawn-OCI work
This commit is contained in:
+25
-11
@@ -23,6 +23,7 @@
|
||||
#include "parse-util.h"
|
||||
#include "path-util.h"
|
||||
#include "pretty-print.h"
|
||||
#include "stat-util.h"
|
||||
#include "strv.h"
|
||||
|
||||
static const char *arg_target = NULL;
|
||||
@@ -69,13 +70,16 @@ static int resize_btrfs(const char *path, int mountfd, int devfd, uint64_t numbl
|
||||
|
||||
#if HAVE_LIBCRYPTSETUP
|
||||
static int resize_crypt_luks_device(dev_t devno, const char *fstype, dev_t main_devno) {
|
||||
char devpath[DEV_NUM_PATH_MAX], main_devpath[DEV_NUM_PATH_MAX];
|
||||
_cleanup_close_ int main_devfd = -1;
|
||||
_cleanup_free_ char *devpath = NULL, *main_devpath = NULL;
|
||||
_cleanup_(crypt_freep) struct crypt_device *cd = NULL;
|
||||
_cleanup_close_ int main_devfd = -1;
|
||||
uint64_t size;
|
||||
int r;
|
||||
|
||||
xsprintf_dev_num_path(main_devpath, "block", main_devno);
|
||||
r = device_path_make_major_minor(S_IFBLK, main_devno, &main_devpath);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to format device major/minor path: %m");
|
||||
|
||||
main_devfd = open(main_devpath, O_RDONLY|O_CLOEXEC);
|
||||
if (main_devfd < 0)
|
||||
return log_error_errno(errno, "Failed to open \"%s\": %m", main_devpath);
|
||||
@@ -85,8 +89,10 @@ static int resize_crypt_luks_device(dev_t devno, const char *fstype, dev_t main_
|
||||
main_devpath);
|
||||
|
||||
log_debug("%s is %"PRIu64" bytes", main_devpath, size);
|
||||
r = device_path_make_major_minor(S_IFBLK, devno, &devpath);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to format major/minor path: %m");
|
||||
|
||||
xsprintf_dev_num_path(devpath, "block", devno);
|
||||
r = crypt_init(&cd, devpath);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "crypt_init(\"%s\") failed: %m", devpath);
|
||||
@@ -115,9 +121,8 @@ static int resize_crypt_luks_device(dev_t devno, const char *fstype, dev_t main_
|
||||
#endif
|
||||
|
||||
static int maybe_resize_slave_device(const char *mountpath, dev_t main_devno) {
|
||||
_cleanup_free_ char *fstype = NULL, *devpath = NULL;
|
||||
dev_t devno;
|
||||
char devpath[DEV_NUM_PATH_MAX];
|
||||
_cleanup_free_ char *fstype = NULL;
|
||||
int r;
|
||||
|
||||
#if HAVE_LIBCRYPTSETUP
|
||||
@@ -137,7 +142,10 @@ static int maybe_resize_slave_device(const char *mountpath, dev_t main_devno) {
|
||||
if (devno == main_devno)
|
||||
return 0;
|
||||
|
||||
xsprintf_dev_num_path(devpath, "block", devno);
|
||||
r = device_path_make_major_minor(S_IFBLK, devno, &devpath);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to format device major/minor path: %m");
|
||||
|
||||
r = probe_filesystem(devpath, &fstype);
|
||||
if (r == -EUCLEAN)
|
||||
return log_warning_errno(r, "Cannot reliably determine probe \"%s\", refusing to proceed.", devpath);
|
||||
@@ -222,12 +230,13 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
dev_t devno;
|
||||
_cleanup_close_ int mountfd = -1, devfd = -1;
|
||||
int blocksize;
|
||||
_cleanup_free_ char *devpath = NULL;
|
||||
uint64_t size, numblocks;
|
||||
char devpath[DEV_NUM_PATH_MAX], fb[FORMAT_BYTES_MAX];
|
||||
char fb[FORMAT_BYTES_MAX];
|
||||
struct statfs sfs;
|
||||
dev_t devno;
|
||||
int blocksize;
|
||||
int r;
|
||||
|
||||
log_setup_service();
|
||||
@@ -264,7 +273,12 @@ int main(int argc, char *argv[]) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
xsprintf_dev_num_path(devpath, "block", devno);
|
||||
r = device_path_make_major_minor(S_IFBLK, devno, &devpath);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to format device major/minor path: %m");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
devfd = open(devpath, O_RDONLY|O_CLOEXEC);
|
||||
if (devfd < 0) {
|
||||
log_error_errno(errno, "Failed to open \"%s\": %m", devpath);
|
||||
|
||||
Reference in New Issue
Block a user