repart: support "nodatacow" in btrfs subvolumes
In btrfs-progs 6.15 it is planned to add a new parameter in mkfs.btrfs --inode-flags, that can set attributes for subvolumes, directories, and files. The current supported attributes are "nodatacow", to disable CoW, and "nodatasum", to disable the checksum. This commit extend the "Subvolunes=" option to understand the "nodatacow" flag for subvolums only. If RepartOffline is enabled it will build the image without loopback devices, using the correct --inode-flags parameters. If RepartOffline is disabled it will use loopback devices and set the btrfs attributes accordingly. Signed-off-by: Alberto Planas <aplanas@suse.com>
This commit is contained in:
committed by
Yu Watanabe
parent
eeedea94da
commit
ab1f4e506f
@@ -1,7 +1,16 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
#pragma once
|
||||
|
||||
#include "basic-forward.h"
|
||||
|
||||
typedef enum BtrfsSubvolFlags {
|
||||
BTRFS_SUBVOL_RO = 1 << 0,
|
||||
BTRFS_SUBVOL_NODATACOW = 1 << 1,
|
||||
_BTRFS_SUBVOL_FLAGS_MASK = BTRFS_SUBVOL_NODATACOW|BTRFS_SUBVOL_RO,
|
||||
_BTRFS_SUBVOL_FLAGS_INVALID = -EINVAL,
|
||||
_BTRFS_SUBVOL_FLAGS_ERRNO_MAX = -ERRNO_MAX, /* Ensure the whole errno range fits into this enum */
|
||||
} BtrfsSubvolFlags;
|
||||
|
||||
int btrfs_validate_subvolume_name(const char *name);
|
||||
|
||||
int btrfs_subvol_make(int dir_fd, const char *path);
|
||||
|
||||
+10
-2
@@ -9,6 +9,7 @@
|
||||
#include "fd-util.h"
|
||||
#include "format-util.h"
|
||||
#include "fs-util.h"
|
||||
#include "hashmap.h"
|
||||
#include "log.h"
|
||||
#include "mkdir.h"
|
||||
#include "path-util.h"
|
||||
@@ -202,7 +203,7 @@ int mkdir_p_safe(const char *prefix, const char *path, mode_t mode, uid_t uid, g
|
||||
return mkdir_p_internal(prefix, path, mode, uid, gid, flags, mkdirat_errno_wrapper);
|
||||
}
|
||||
|
||||
int mkdir_p_root_full(const char *root, const char *p, uid_t uid, gid_t gid, mode_t m, usec_t ts, char **subvolumes) {
|
||||
int mkdir_p_root_full(const char *root, const char *p, uid_t uid, gid_t gid, mode_t m, usec_t ts, Hashmap *subvolumes) {
|
||||
_cleanup_free_ char *pp = NULL, *bn = NULL;
|
||||
_cleanup_close_ int dfd = -EBADF;
|
||||
int r;
|
||||
@@ -237,10 +238,17 @@ int mkdir_p_root_full(const char *root, const char *p, uid_t uid, gid_t gid, mod
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
XOpenFlags flags = 0;
|
||||
if (hashmap_contains(subvolumes, p)) {
|
||||
flags = XO_SUBVOLUME;
|
||||
if ((PTR_TO_INT(hashmap_get(subvolumes, p)) & BTRFS_SUBVOL_NODATACOW))
|
||||
flags |= XO_NOCOW;
|
||||
}
|
||||
|
||||
_cleanup_close_ int nfd = xopenat_full(
|
||||
dfd, bn,
|
||||
O_DIRECTORY|O_CREAT|O_EXCL|O_NOFOLLOW|O_CLOEXEC,
|
||||
path_strv_contains(subvolumes, p) ? XO_SUBVOLUME : 0,
|
||||
flags,
|
||||
m);
|
||||
if (nfd == -EEXIST)
|
||||
return 0;
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ static inline int mkdir_parents(const char *path, mode_t mode) {
|
||||
int mkdir_parents_safe(const char *prefix, const char *path, mode_t mode, uid_t uid, gid_t gid, MkdirFlags flags);
|
||||
int mkdir_p(const char *path, mode_t mode);
|
||||
int mkdir_p_safe(const char *prefix, const char *path, mode_t mode, uid_t uid, gid_t gid, MkdirFlags flags);
|
||||
int mkdir_p_root_full(const char *root, const char *p, uid_t uid, gid_t gid, mode_t m, usec_t ts, char **subvolumes);
|
||||
int mkdir_p_root_full(const char *root, const char *p, uid_t uid, gid_t gid, mode_t m, usec_t ts, Hashmap *subvolumes);
|
||||
static inline int mkdir_p_root(const char *root, const char *p, uid_t uid, gid_t gid, mode_t m) {
|
||||
return mkdir_p_root_full(root, p, uid, gid, m, USEC_INFINITY, NULL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user