Merge pull request #33825 from DaanDeMeyer/chattr
repart: Create disk image file with copy-on-write disabled on btrfs
This commit is contained in:
+33
-8
@@ -798,6 +798,7 @@ static int fd_copy_regular(
|
||||
void *userdata) {
|
||||
|
||||
_cleanup_close_ int fdf = -EBADF, fdt = -EBADF;
|
||||
unsigned attrs = 0;
|
||||
int r, q;
|
||||
|
||||
assert(st);
|
||||
@@ -813,6 +814,10 @@ static int fd_copy_regular(
|
||||
if (fdf < 0)
|
||||
return fdf;
|
||||
|
||||
r = read_attr_fd(fdf, &attrs);
|
||||
if (r < 0 && !ERRNO_IS_NOT_SUPPORTED(r) && r != -ELOOP)
|
||||
return r;
|
||||
|
||||
if (copy_flags & COPY_MAC_CREATE) {
|
||||
r = mac_selinux_create_file_prepare_at(dt, to, S_IFREG);
|
||||
if (r < 0)
|
||||
@@ -824,6 +829,9 @@ static int fd_copy_regular(
|
||||
if (fdt < 0)
|
||||
return -errno;
|
||||
|
||||
if (attrs != 0)
|
||||
(void) chattr_full(fdt, NULL, attrs, CHATTR_EARLY_FL, NULL, NULL, CHATTR_FALLBACK_BITWISE);
|
||||
|
||||
r = copy_bytes_full(fdf, fdt, UINT64_MAX, copy_flags, NULL, NULL, progress, userdata);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
@@ -839,6 +847,9 @@ static int fd_copy_regular(
|
||||
(void) futimens(fdt, (struct timespec[]) { st->st_atim, st->st_mtim });
|
||||
(void) copy_xattr(fdf, NULL, fdt, NULL, copy_flags);
|
||||
|
||||
if (attrs != 0)
|
||||
(void) chattr_full(fdt, NULL, attrs, ~CHATTR_EARLY_FL, NULL, NULL, CHATTR_FALLBACK_BITWISE);
|
||||
|
||||
if (FLAGS_SET(copy_flags, COPY_VERIFY_LINKED)) {
|
||||
r = fd_verify_linked(fdf);
|
||||
if (r < 0)
|
||||
@@ -1413,6 +1424,7 @@ int copy_file_at_full(
|
||||
|
||||
_cleanup_close_ int fdf = -EBADF, fdt = -EBADF;
|
||||
struct stat st;
|
||||
unsigned attrs = 0;
|
||||
int r;
|
||||
|
||||
assert(dir_fdf >= 0 || dir_fdf == AT_FDCWD);
|
||||
@@ -1430,6 +1442,10 @@ int copy_file_at_full(
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = read_attr_at(dir_fdf, from, &attrs);
|
||||
if (r < 0 && !ERRNO_IS_NOT_SUPPORTED(r) && r != -ELOOP)
|
||||
return r;
|
||||
|
||||
WITH_UMASK(0000) {
|
||||
fdt = xopenat_lock_full(dir_fdt, to,
|
||||
flags|O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY,
|
||||
@@ -1446,8 +1462,10 @@ int copy_file_at_full(
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (chattr_mask != 0)
|
||||
(void) chattr_fd(fdt, chattr_flags, chattr_mask & CHATTR_EARLY_FL, NULL);
|
||||
attrs = (attrs & ~chattr_mask) | (chattr_flags & chattr_mask);
|
||||
|
||||
if (attrs != 0)
|
||||
(void) chattr_full(fdt, NULL, attrs, CHATTR_EARLY_FL, NULL, NULL, CHATTR_FALLBACK_BITWISE);
|
||||
|
||||
r = copy_bytes_full(fdf, fdt, UINT64_MAX, copy_flags & ~COPY_LOCK_BSD, NULL, NULL, progress_bytes, userdata);
|
||||
if (r < 0)
|
||||
@@ -1462,8 +1480,8 @@ int copy_file_at_full(
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (chattr_mask != 0)
|
||||
(void) chattr_fd(fdt, chattr_flags, chattr_mask & ~CHATTR_EARLY_FL, NULL);
|
||||
if (attrs != 0)
|
||||
(void) chattr_full(fdt, NULL, attrs, ~CHATTR_EARLY_FL, NULL, NULL, CHATTR_FALLBACK_BITWISE);
|
||||
|
||||
if (copy_flags & (COPY_FSYNC|COPY_FSYNC_FULL)) {
|
||||
if (fsync(fdt) < 0) {
|
||||
@@ -1508,6 +1526,7 @@ int copy_file_atomic_at_full(
|
||||
|
||||
_cleanup_(unlink_and_freep) char *t = NULL;
|
||||
_cleanup_close_ int fdt = -EBADF;
|
||||
unsigned attrs = 0;
|
||||
int r;
|
||||
|
||||
assert(to);
|
||||
@@ -1524,8 +1543,14 @@ int copy_file_atomic_at_full(
|
||||
if (fdt < 0)
|
||||
return fdt;
|
||||
|
||||
if (chattr_mask != 0)
|
||||
(void) chattr_fd(fdt, chattr_flags, chattr_mask & CHATTR_EARLY_FL, NULL);
|
||||
r = read_attr_at(dir_fdf, from, &attrs);
|
||||
if (r < 0 && !ERRNO_IS_NOT_SUPPORTED(r) && r != -ELOOP)
|
||||
return r;
|
||||
|
||||
attrs = (attrs & ~chattr_mask) | (chattr_flags & chattr_mask);
|
||||
|
||||
if (attrs != 0)
|
||||
(void) chattr_full(fdt, NULL, attrs, CHATTR_EARLY_FL, NULL, NULL, CHATTR_FALLBACK_BITWISE);
|
||||
|
||||
r = copy_file_fd_at_full(dir_fdf, from, fdt, copy_flags, progress_bytes, userdata);
|
||||
if (r < 0)
|
||||
@@ -1546,8 +1571,8 @@ int copy_file_atomic_at_full(
|
||||
|
||||
t = mfree(t);
|
||||
|
||||
if (chattr_mask != 0)
|
||||
(void) chattr_fd(fdt, chattr_flags, chattr_mask & ~CHATTR_EARLY_FL, NULL);
|
||||
if (attrs != 0)
|
||||
(void) chattr_full(fdt, NULL, attrs, ~CHATTR_EARLY_FL, NULL, NULL, CHATTR_FALLBACK_BITWISE);
|
||||
|
||||
r = close_nointr(TAKE_FD(fdt)); /* even if this fails, the fd is now invalidated */
|
||||
if (r < 0)
|
||||
|
||||
@@ -1070,7 +1070,7 @@ int image_rename(Image *i, const char *new_name) {
|
||||
|
||||
case IMAGE_DIRECTORY:
|
||||
/* Turn of the immutable bit while we rename the image, so that we can rename it */
|
||||
(void) read_attr_path(i->path, &file_attr);
|
||||
(void) read_attr_at(AT_FDCWD, i->path, &file_attr);
|
||||
|
||||
if (file_attr & FS_IMMUTABLE_FL)
|
||||
(void) chattr_path(i->path, 0, FS_IMMUTABLE_FL, NULL);
|
||||
@@ -1205,8 +1205,7 @@ int image_clone(Image *i, const char *new_name, bool read_only) {
|
||||
case IMAGE_RAW:
|
||||
new_path = strjoina("/var/lib/machines/", new_name, ".raw");
|
||||
|
||||
r = copy_file_atomic_full(i->path, new_path, read_only ? 0444 : 0644, FS_NOCOW_FL, FS_NOCOW_FL,
|
||||
COPY_REFLINK|COPY_CRTIME, NULL, NULL);
|
||||
r = copy_file_atomic(i->path, new_path, read_only ? 0444 : 0644, COPY_REFLINK|COPY_CRTIME);
|
||||
break;
|
||||
|
||||
case IMAGE_BLOCK:
|
||||
|
||||
@@ -227,6 +227,16 @@ static inline int run_test_table(void) {
|
||||
} \
|
||||
})
|
||||
|
||||
#define ASSERT_FAIL(expr) \
|
||||
({ \
|
||||
typeof(expr) _result = (expr); \
|
||||
if (_result >= 0) { \
|
||||
log_error_errno(_result, "%s:%i: Assertion failed: expected \"%s\" to fail, but it succeeded", \
|
||||
PROJECT_FILE, __LINE__, #expr); \
|
||||
abort(); \
|
||||
} \
|
||||
})
|
||||
|
||||
#define ASSERT_ERROR(expr1, expr2) \
|
||||
({ \
|
||||
int _expr1 = (expr1); \
|
||||
@@ -419,3 +429,30 @@ static inline int run_test_table(void) {
|
||||
abort(); \
|
||||
} \
|
||||
})
|
||||
|
||||
|
||||
#define ASSERT_EQ_ID128(expr1, expr2) \
|
||||
({ \
|
||||
typeof(expr1) _expr1 = (expr1); \
|
||||
typeof(expr2) _expr2 = (expr2); \
|
||||
if (!sd_id128_equal(_expr1, _expr2)) { \
|
||||
log_error("%s:%i: Assertion failed: \"%s == %s\", but \"%s != %s\"", \
|
||||
PROJECT_FILE, __LINE__, \
|
||||
#expr1, #expr2, \
|
||||
SD_ID128_TO_STRING(_expr1), SD_ID128_TO_STRING(_expr2)); \
|
||||
abort(); \
|
||||
} \
|
||||
})
|
||||
|
||||
#define ASSERT_NE_ID128(expr1, expr2) \
|
||||
({ \
|
||||
typeof(expr1) _expr1 = (expr1); \
|
||||
typeof(expr2) _expr2 = (expr2); \
|
||||
if (sd_id128_equal(_expr1, _expr2)) { \
|
||||
log_error("%s:%i: Assertion failed: \"%s != %s\", but \"%s == %s\"", \
|
||||
PROJECT_FILE, __LINE__, \
|
||||
#expr1, #expr2, \
|
||||
SD_ID128_TO_STRING(_expr1), SD_ID128_TO_STRING(_expr2)); \
|
||||
abort(); \
|
||||
} \
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user