From patchwork Mon Oct 14 09:40:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13834524 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 800D0156C5F; Mon, 14 Oct 2024 09:41:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728898869; cv=none; b=V57w4ntQWQgBP+rEEkCuM6diTybrIhQVCZL+uyn0p8gdZsgP8KIuD/BknX7ODaMr3WWRg4vtFH62bFMQYgWz+msp3IR1zyf3trGzBOS112PIXfX4l7JFpOJ3MoWMf/rn6HK4yp9hZisbGYWSzYQaCxIRO3wlpqYM9lMFp1EQMC8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728898869; c=relaxed/simple; bh=wTAC5m5GXry4oLIxvLmVbB7YbXNsZi4/fpreoeeWhnM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SrltoNRmHdHzHfIgeJlhS59dIADFaXFSssqtb3hCig/I1ZPwzi0+yQKr1y4JucVMZbzSp/fUeQBX2mgG2mNWhez8QdU2sSpIPz8qRx/+q1ufSmxgqAVJ4SsssAVW40o0KFrx/9jDvOm8gUVl9tyRIE+IIhcxN/wxfJTvtcCI6aU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=F+Ah6Dei; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="F+Ah6Dei" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D309EC4CED0; Mon, 14 Oct 2024 09:41:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728898869; bh=wTAC5m5GXry4oLIxvLmVbB7YbXNsZi4/fpreoeeWhnM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=F+Ah6Dei6saguIP9hjagPM12w2Gz5pt+t3UdNy1qYKZbC+ZdbasdnFZ5iRTdc3mNB OBfvlQxOq6b5gVcD4ebctAGAvJn6y+x2s4daeO9mKtGLq3hkPkO9PiyGrmoEF52vxm 2b7e5QWeosa7MJsjYxhd39Y4ja9c7SqzpBcyamaONtoKSHZECGF1fnKzMmAUOCn/Ur YyKEK4XGxCD67MR1J49rQ6KBcW0X+XRx7Q20vxRH+3Ni1xRg9CR07mwtS+u5sB2zlO MR+EtqExa/kiGMVj/9HMU7cJgrEoKky0Gxc1Vf5eRZ2Ck53tYOPMtY5D+Jew/GGkMX 4+rjbCtV4iPSA== From: Christian Brauner Date: Mon, 14 Oct 2024 11:40:56 +0200 Subject: [PATCH v3 1/5] fs: add helper to use mount option as path or fd Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241014-work-overlayfs-v3-1-32b3fed1286e@kernel.org> References: <20241014-work-overlayfs-v3-0-32b3fed1286e@kernel.org> In-Reply-To: <20241014-work-overlayfs-v3-0-32b3fed1286e@kernel.org> To: Miklos Szeredi , Amir Goldstein Cc: Josef Bacik , linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org, Christian Brauner X-Mailer: b4 0.15-dev-2a633 X-Developer-Signature: v=1; a=openpgp-sha256; l=2607; i=brauner@kernel.org; h=from:subject:message-id; bh=wTAC5m5GXry4oLIxvLmVbB7YbXNsZi4/fpreoeeWhnM=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaTzPDc8ntm63vhk2K6O966bVSJe5L0PE+5cw7DtsFruw pxpu94bdZSyMIhxMciKKbI4tJuEyy3nqdhslKkBM4eVCWQIAxenAEzEzp6R4YlT+Y7d9qdFvacd 12xewV6qt/cCp6OMfgn/I1P+yZZS1xj+8GSy/WJwlpzk2Xzql4zCXgubm9+m3/N4dlXyh+KBi0f E2AE= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Allow filesystems to use a mount option either as a file or path. Signed-off-by: Christian Brauner --- fs/fs_parser.c | 20 ++++++++++++++++++++ include/linux/fs_parser.h | 5 ++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/fs/fs_parser.c b/fs/fs_parser.c index 24727ec34e5aa434364e87879cccf9fe1ec19d37..8f583b814e6e4377cf0611c11abbf24168a58d74 100644 --- a/fs/fs_parser.c +++ b/fs/fs_parser.c @@ -308,6 +308,26 @@ int fs_param_is_fd(struct p_log *log, const struct fs_parameter_spec *p, } EXPORT_SYMBOL(fs_param_is_fd); +int fs_param_is_file_or_string(struct p_log *log, + const struct fs_parameter_spec *p, + struct fs_parameter *param, + struct fs_parse_result *result) +{ + switch (param->type) { + case fs_value_is_string: + return fs_param_is_string(log, p, param, result); + case fs_value_is_file: + result->uint_32 = param->dirfd; + if (result->uint_32 <= INT_MAX) + return 0; + break; + default: + break; + } + return fs_param_bad_value(log, param); +} +EXPORT_SYMBOL(fs_param_is_file_or_string); + int fs_param_is_uid(struct p_log *log, const struct fs_parameter_spec *p, struct fs_parameter *param, struct fs_parse_result *result) { diff --git a/include/linux/fs_parser.h b/include/linux/fs_parser.h index 6cf713a7e6c6fc2402a68c87036264eaed921432..3cef566088fcf7e04c569acd849a785462c33f17 100644 --- a/include/linux/fs_parser.h +++ b/include/linux/fs_parser.h @@ -28,7 +28,8 @@ typedef int fs_param_type(struct p_log *, */ fs_param_type fs_param_is_bool, fs_param_is_u32, fs_param_is_s32, fs_param_is_u64, fs_param_is_enum, fs_param_is_string, fs_param_is_blob, fs_param_is_blockdev, - fs_param_is_path, fs_param_is_fd, fs_param_is_uid, fs_param_is_gid; + fs_param_is_path, fs_param_is_fd, fs_param_is_uid, fs_param_is_gid, + fs_param_is_file_or_string; /* * Specification of the type of value a parameter wants. @@ -133,6 +134,8 @@ static inline bool fs_validate_description(const char *name, #define fsparam_bdev(NAME, OPT) __fsparam(fs_param_is_blockdev, NAME, OPT, 0, NULL) #define fsparam_path(NAME, OPT) __fsparam(fs_param_is_path, NAME, OPT, 0, NULL) #define fsparam_fd(NAME, OPT) __fsparam(fs_param_is_fd, NAME, OPT, 0, NULL) +#define fsparam_file_or_string(NAME, OPT) \ + __fsparam(fs_param_is_file_or_string, NAME, OPT, 0, NULL) #define fsparam_uid(NAME, OPT) __fsparam(fs_param_is_uid, NAME, OPT, 0, NULL) #define fsparam_gid(NAME, OPT) __fsparam(fs_param_is_gid, NAME, OPT, 0, NULL) From patchwork Mon Oct 14 09:40:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13834525 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B43D15B0EE; Mon, 14 Oct 2024 09:41:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728898871; cv=none; b=Iu6HNtfToLoqhUZsl0ztmAtZJE7fBb3GA4YdXykZz7N0DcYeZ1SoeNLEhfVuxFh71qTZ5ApRSNJW1aFg9PYfFfKub1gdJcELeRR7u1+r+13vYCqQll5JRYDSTMHYBbuOD73mRJlk2KvhXzFOLajyL7jZRvXmMsN+TI0/D/rFfKg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728898871; c=relaxed/simple; bh=oS0VlFmrovOBWOMBqrVsyJ9XuzXsXw2KKkMkW9YTpH8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZhSW6pwFJuQE+GK9YdMBm9CejDBsRFnEI4lgB6VebuImAC6HHGDXf1ShH48YmePTVKcJcCK7hIf58jMsFgg+j2z2PCnvQeKR+DtGGOi90kzALB8qlOYEewuUl4A5Mqp4Et6DB3kQLxwN+ZUSJZ1KwsBO56Q4G3IhxftoRiFzzbI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VE4aH/AZ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VE4aH/AZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8EA72C4CEC3; Mon, 14 Oct 2024 09:41:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728898870; bh=oS0VlFmrovOBWOMBqrVsyJ9XuzXsXw2KKkMkW9YTpH8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=VE4aH/AZMF0jat5D+2rqomzh6IqU+tytpRbMPBdQ//r5kxj4F2vwfTW3pc3WMlnbC Ovet3rA8YM+WRQqyF1Pyck9hGznrU6ZtHM5W05Ow9WF1ck2TN9qiGVsKAtSvTB1fnR ydEFMcHYTAKzZkuZPSoL5W5RpewHZ/G+/+hk+cmZb9rkz4rJJC5jF0l0VxW+JqcF8S 1mikMlr52W1C/LLCyPDzm0rdjZpQr0aaBrkR8RG3rs4V/hlOt5hkUarswM/Bnsrias z0Qku20rOwanzRIVtnYkhKebGhtJInemPDeQuL6fs2UPT14pqwEvlnDdhZ/DrepT/W LPS7lXtp7p0hA== From: Christian Brauner Date: Mon, 14 Oct 2024 11:40:57 +0200 Subject: [PATCH v3 2/5] ovl: specify layers via file descriptors Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241014-work-overlayfs-v3-2-32b3fed1286e@kernel.org> References: <20241014-work-overlayfs-v3-0-32b3fed1286e@kernel.org> In-Reply-To: <20241014-work-overlayfs-v3-0-32b3fed1286e@kernel.org> To: Miklos Szeredi , Amir Goldstein Cc: Josef Bacik , linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org, Christian Brauner X-Mailer: b4 0.15-dev-2a633 X-Developer-Signature: v=1; a=openpgp-sha256; l=5893; i=brauner@kernel.org; h=from:subject:message-id; bh=oS0VlFmrovOBWOMBqrVsyJ9XuzXsXw2KKkMkW9YTpH8=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaTzPDc0MmBz+ZeWoFDxr3FF9S+J1sUT/Hfs5U+0C97PX fBwY8OnjlIWBjEuBlkxRRaHdpNwueU8FZuNMjVg5rAygQxh4OIUgInU3Gf4H9694Vx/2/9dxuof rgfH8+14o3t0xfPZic+sEs/rsPi7SjIy/A+t5Lv5m9mjWOzR6lJRLfdXz/MKmeMPiX/M4YjmuPC eBQA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Currently overlayfs only allows specifying layers through path names. This is inconvenient for users such as systemd that want to assemble an overlayfs mount purely based on file descriptors. This enables user to specify both: fsconfig(fd_overlay, FSCONFIG_SET_FD, "upperdir+", NULL, fd_upper); fsconfig(fd_overlay, FSCONFIG_SET_FD, "workdir+", NULL, fd_work); fsconfig(fd_overlay, FSCONFIG_SET_FD, "lowerdir+", NULL, fd_lower1); fsconfig(fd_overlay, FSCONFIG_SET_FD, "lowerdir+", NULL, fd_lower2); in addition to: fsconfig(fd_overlay, FSCONFIG_SET_STRING, "upperdir+", "/upper", 0); fsconfig(fd_overlay, FSCONFIG_SET_STRING, "workdir+", "/work", 0); fsconfig(fd_overlay, FSCONFIG_SET_STRING, "lowerdir+", "/lower1", 0); fsconfig(fd_overlay, FSCONFIG_SET_STRING, "lowerdir+", "/lower2", 0); Signed-off-by: Christian Brauner --- fs/overlayfs/params.c | 116 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 91 insertions(+), 25 deletions(-) diff --git a/fs/overlayfs/params.c b/fs/overlayfs/params.c index e42546c6c5dfbea930414856d791e3e4424a999e..1115c22deca0cb97a2c70fdff5eac1b4f09e504d 100644 --- a/fs/overlayfs/params.c +++ b/fs/overlayfs/params.c @@ -141,10 +141,10 @@ static int ovl_verity_mode_def(void) const struct fs_parameter_spec ovl_parameter_spec[] = { fsparam_string_empty("lowerdir", Opt_lowerdir), - fsparam_string("lowerdir+", Opt_lowerdir_add), - fsparam_string("datadir+", Opt_datadir_add), - fsparam_string("upperdir", Opt_upperdir), - fsparam_string("workdir", Opt_workdir), + fsparam_file_or_string("lowerdir+", Opt_lowerdir_add), + fsparam_file_or_string("datadir+", Opt_datadir_add), + fsparam_file_or_string("upperdir", Opt_upperdir), + fsparam_file_or_string("workdir", Opt_workdir), fsparam_flag("default_permissions", Opt_default_permissions), fsparam_enum("redirect_dir", Opt_redirect_dir, ovl_parameter_redirect_dir), fsparam_enum("index", Opt_index, ovl_parameter_bool), @@ -367,40 +367,100 @@ static void ovl_add_layer(struct fs_context *fc, enum ovl_opt layer, } } -static int ovl_parse_layer(struct fs_context *fc, const char *layer_name, enum ovl_opt layer) +static inline bool is_upper_layer(enum ovl_opt layer) +{ + return layer == Opt_upperdir || layer == Opt_workdir; +} + +/* Handle non-file descriptor-based layer options that require path lookup. */ +static inline int ovl_kern_path(const char *layer_name, struct path *layer_path, + enum ovl_opt layer) { - char *name = kstrdup(layer_name, GFP_KERNEL); - bool upper = (layer == Opt_upperdir || layer == Opt_workdir); - struct path path; int err; + switch (layer) { + case Opt_upperdir: + fallthrough; + case Opt_workdir: + fallthrough; + case Opt_lowerdir: + err = ovl_mount_dir(layer_name, layer_path); + break; + case Opt_lowerdir_add: + fallthrough; + case Opt_datadir_add: + err = ovl_mount_dir_noesc(layer_name, layer_path); + break; + default: + WARN_ON_ONCE(true); + err = -EINVAL; + } + + return err; +} + +static int ovl_do_parse_layer(struct fs_context *fc, const char *layer_name, + struct path *layer_path, enum ovl_opt layer) +{ + char *name __free(kfree) = kstrdup(layer_name, GFP_KERNEL); + bool upper; + int err = 0; + if (!name) return -ENOMEM; - if (upper || layer == Opt_lowerdir) - err = ovl_mount_dir(name, &path); - else - err = ovl_mount_dir_noesc(name, &path); + upper = is_upper_layer(layer); + err = ovl_mount_dir_check(fc, layer_path, layer, name, upper); if (err) - goto out_free; - - err = ovl_mount_dir_check(fc, &path, layer, name, upper); - if (err) - goto out_put; + return err; if (!upper) { err = ovl_ctx_realloc_lower(fc); if (err) - goto out_put; + return err; } /* Store the user provided path string in ctx to show in mountinfo */ - ovl_add_layer(fc, layer, &path, &name); + ovl_add_layer(fc, layer, layer_path, &name); + return err; +} + +static int ovl_parse_layer(struct fs_context *fc, struct fs_parameter *param, + enum ovl_opt layer) +{ + struct path layer_path __free(path_put) = {}; + int err = 0; + + switch (param->type) { + case fs_value_is_string: + err = ovl_kern_path(param->string, &layer_path, layer); + if (err) + return err; + err = ovl_do_parse_layer(fc, param->string, &layer_path, layer); + break; + case fs_value_is_file: { + char *buf __free(kfree); + char *layer_name; + + buf = kmalloc(PATH_MAX, GFP_KERNEL_ACCOUNT); + if (!buf) + return -ENOMEM; + + layer_path = param->file->f_path; + path_get(&layer_path); + + layer_name = d_path(&layer_path, buf, PATH_MAX); + if (IS_ERR(layer_name)) + return PTR_ERR(layer_name); + + err = ovl_do_parse_layer(fc, layer_name, &layer_path, layer); + break; + } + default: + WARN_ON_ONCE(true); + err = -EINVAL; + } -out_put: - path_put(&path); -out_free: - kfree(name); return err; } @@ -474,7 +534,13 @@ static int ovl_parse_param_lowerdir(const char *name, struct fs_context *fc) iter = dup; for (nr = 0; nr < nr_lower; nr++) { - err = ovl_parse_layer(fc, iter, Opt_lowerdir); + struct path path __free(path_put) = {}; + + err = ovl_kern_path(iter, &path, Opt_lowerdir); + if (err) + goto out_err; + + err = ovl_do_parse_layer(fc, iter, &path, Opt_lowerdir); if (err) goto out_err; @@ -555,7 +621,7 @@ static int ovl_parse_param(struct fs_context *fc, struct fs_parameter *param) case Opt_datadir_add: case Opt_upperdir: case Opt_workdir: - err = ovl_parse_layer(fc, param->string, opt); + err = ovl_parse_layer(fc, param, opt); break; case Opt_default_permissions: config->default_permissions = true; From patchwork Mon Oct 14 09:40:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13834526 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B781B15B97E; Mon, 14 Oct 2024 09:41:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728898872; cv=none; b=lqStyGq2MX7FIeXtSLeBHeSC8yCbSfetgnKGg4pyxtZetGuBVEjTGeX3pFHgjgO/BzA6WNu1tCEV3bGPu+NZNYpnJYPXvu1bE3Vnh+KrSH83w+A96ZeCSt2HgWJSrN32crYHU5aMwl6bgUBRGI/eR7A/VlhnQo06piY0IkXKZg0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728898872; c=relaxed/simple; bh=Ai9orcwJKxMB1d2lHTAIh+DXnKUDBg6ZOYAJ/xf+E8A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aVFdcS8pzqN3iHObHEcTU1t59NX2CR4jH4uPxbVPvGvuvpn9LiWzdGy8Bk99sSi6w+vWkXjSLllN5f5IjSElLl97/HwVUmUGCuFUaH+pYdB2kImyK099Vma5GSryjS2KpqnZ2rJ2YT9gdOmkXDMM3rR8WweMhCbFw5OWJQrSPt0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MLmpB9nT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MLmpB9nT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 490B1C4CEC7; Mon, 14 Oct 2024 09:41:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728898872; bh=Ai9orcwJKxMB1d2lHTAIh+DXnKUDBg6ZOYAJ/xf+E8A=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=MLmpB9nTnCxt6jgwre4JgWJxNQ4qesFfYg03Go/AmVC/75urAyo9fePkw2ag+jFbI A2+6U++bJonh/otTWxQatbi/QJ0tcJjXNBlvuCF0FrJDQrT52YR2EpgVHfZntLzkPs 3iK+jZt7kSmqMVQepCxBW88DUKi43wV9MJ0MNBRg7mawW3H90DV+ZsXcMzz0O/k2q+ wPd910+Fhz5TVMrR/lRyR5ep54+emVqNrFyWuLihMedNuDjLiyLrfJhO8xz4Za4470 9dRAQ3LSKhMKz47PKrzMiA29B2r3IGz/GioVERmJHj53L0xeuEz5V2uyA9CCJHs7PN N5wRHNJOZaRUA== From: Christian Brauner Date: Mon, 14 Oct 2024 11:40:58 +0200 Subject: [PATCH v3 3/5] Documentation,ovl: document new file descriptor based layers Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241014-work-overlayfs-v3-3-32b3fed1286e@kernel.org> References: <20241014-work-overlayfs-v3-0-32b3fed1286e@kernel.org> In-Reply-To: <20241014-work-overlayfs-v3-0-32b3fed1286e@kernel.org> To: Miklos Szeredi , Amir Goldstein Cc: Josef Bacik , linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org, Christian Brauner X-Mailer: b4 0.15-dev-2a633 X-Developer-Signature: v=1; a=openpgp-sha256; l=1521; i=brauner@kernel.org; h=from:subject:message-id; bh=Ai9orcwJKxMB1d2lHTAIh+DXnKUDBg6ZOYAJ/xf+E8A=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaTzPDdcvnH3wk7n+rsK94uPXn82l23/1Huhq+sbz7sd2 MDwyHhTekcpC4MYF4OsmCKLQ7tJuNxynorNRpkaMHNYmUCGMHBxCsBEFukxMhzcpei0XLH4/P+g XaxGHGtXf3k09bBxQfPJ/VrMmwRzHX0Y/od79TwKsI5OKfQ65ldk3Mn4Sye2TO5Aw9YFHhqcu/c nMAIA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Add a minimal example how to specify layers via file descriptors. Signed-off-by: Christian Brauner --- Documentation/filesystems/overlayfs.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Documentation/filesystems/overlayfs.rst b/Documentation/filesystems/overlayfs.rst index 3436447123409726cbd78badea2f8b4f002e0640..4c8387e1c88068fa10c640191fe3bcc20587f6b0 100644 --- a/Documentation/filesystems/overlayfs.rst +++ b/Documentation/filesystems/overlayfs.rst @@ -440,6 +440,23 @@ For example:: fsconfig(fs_fd, FSCONFIG_SET_STRING, "datadir+", "/do2", 0); +Specifying layers via file descriptors +-------------------------------------- + +Since kernel v6.13, overlayfs supports specifying layers via file descriptors in +addition to specifying them as paths. This feature is available for the +"datadir+", "lowerdir+", "upperdir", and "workdir+" mount options with the +fsconfig syscall from the new mount api:: + + fsconfig(fs_fd, FSCONFIG_SET_FD, "lowerdir+", NULL, fd_lower1); + fsconfig(fs_fd, FSCONFIG_SET_FD, "lowerdir+", NULL, fd_lower2); + fsconfig(fs_fd, FSCONFIG_SET_FD, "lowerdir+", NULL, fd_lower3); + fsconfig(fs_fd, FSCONFIG_SET_FD, "datadir+", NULL, fd_data1); + fsconfig(fs_fd, FSCONFIG_SET_FD, "datadir+", NULL, fd_data2); + fsconfig(fs_fd, FSCONFIG_SET_FD, "workdir", NULL, fd_work); + fsconfig(fs_fd, FSCONFIG_SET_FD, "upperdir", NULL, fd_upper); + + fs-verity support ----------------- From patchwork Mon Oct 14 09:40:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13834527 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A35915CD60; Mon, 14 Oct 2024 09:41:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728898874; cv=none; b=e63xSiAaGZrVGDm+eGJ7Th6u7g4TBCusjg3aEeku5lWGzw8Wpn80zOG8huJZEQhq588J4mwF6tBO1Al4eK+yxmogKMa+JqEmPF8Wch8uDZPF3fM0+KgMqwV4Uir0u0QInu5U/NhAUQPchMAn3hZxu55RtKYKybOdvBWjpuZ+4KE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728898874; c=relaxed/simple; bh=KRWLagaS4YguCRS2vcI21OA10tbn8Q0Kj2MV+AwTbjI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=O/+ly+QThgMrMPC3pIYH/cEkZxfujy7At1zg6YoIJJ850PSyFe03MflrGa4cfbLr2BKp1AyzhdzqoNe057mwResla3/zGgO5MXHQXX2uDaNJHS34VGbxIc4pZqCzRJQ2rzYc+M7um0kUS0BGfPOVeaAJxiyh3X5XlhYwADuOdcQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CoFyqtd5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CoFyqtd5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02798C4CEC3; Mon, 14 Oct 2024 09:41:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728898874; bh=KRWLagaS4YguCRS2vcI21OA10tbn8Q0Kj2MV+AwTbjI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=CoFyqtd593pbti6vA7WDDqDR9wIfIgZDlqMI9162QReGdF8+5yhHXsZ3o9oXJAA09 H/EOLDy+jDnqfQ8aS4NWYz53+v36dDueOIjilkbQqPVscYCImU8hf0MO6wpMJxXPQx JJqvZSHlYxgxbF/U4gNQh9vIU7CkgeS7u+8B8kuszFpb9KZInJrGd5yKUU9tVHTV4b s5vkZAd37Y0QIomA9yDU2BwZRgeyzkUdkmKql2i/fNkLOfxGLmkxDchflHfLeMI6N2 O6XvlYd8dhTAPw8NnrzPi7ltAwtRAvOMMQ2RYshr59bZ4mJAW7f65keIJ7DwNpRCl5 E5PDF+ThA5/Ng== From: Christian Brauner Date: Mon, 14 Oct 2024 11:40:59 +0200 Subject: [PATCH v3 4/5] selftests: use shared header Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241014-work-overlayfs-v3-4-32b3fed1286e@kernel.org> References: <20241014-work-overlayfs-v3-0-32b3fed1286e@kernel.org> In-Reply-To: <20241014-work-overlayfs-v3-0-32b3fed1286e@kernel.org> To: Miklos Szeredi , Amir Goldstein Cc: Josef Bacik , linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org, Christian Brauner X-Mailer: b4 0.15-dev-2a633 X-Developer-Signature: v=1; a=openpgp-sha256; l=3280; i=brauner@kernel.org; h=from:subject:message-id; bh=KRWLagaS4YguCRS2vcI21OA10tbn8Q0Kj2MV+AwTbjI=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaTzPDecsOWoT8sfEcY5KWwnRR99WWLqfNDhwKXz/8sqe 4RlXPT8OkpZGMS4GGTFFFkc2k3C5ZbzVGw2ytSAmcPKBDKEgYtTACbCEMfwP7vgxcbDrQ6Xf+k3 CYq99XgYt2bL5xdL3+3MKGQtf12RpsLIsFy3Xmfl6f6Xzza5Fzxs3ZW3bv6WFOP6q7bCiS+bwo0 VGQA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 So that we don't have to redefine the same system calls over and over. Signed-off-by: Christian Brauner --- .../selftests/filesystems/overlayfs/dev_in_maps.c | 27 +------------- .../selftests/filesystems/overlayfs/wrappers.h | 43 ++++++++++++++++++++++ 2 files changed, 44 insertions(+), 26 deletions(-) diff --git a/tools/testing/selftests/filesystems/overlayfs/dev_in_maps.c b/tools/testing/selftests/filesystems/overlayfs/dev_in_maps.c index 2862aae58b79acbe175ab6b36b42798bb99a2225..3b796264223f81fc753d0adaeccc04077023520b 100644 --- a/tools/testing/selftests/filesystems/overlayfs/dev_in_maps.c +++ b/tools/testing/selftests/filesystems/overlayfs/dev_in_maps.c @@ -17,32 +17,7 @@ #include "../../kselftest.h" #include "log.h" - -static int sys_fsopen(const char *fsname, unsigned int flags) -{ - return syscall(__NR_fsopen, fsname, flags); -} - -static int sys_fsconfig(int fd, unsigned int cmd, const char *key, const char *value, int aux) -{ - return syscall(__NR_fsconfig, fd, cmd, key, value, aux); -} - -static int sys_fsmount(int fd, unsigned int flags, unsigned int attr_flags) -{ - return syscall(__NR_fsmount, fd, flags, attr_flags); -} -static int sys_mount(const char *src, const char *tgt, const char *fst, - unsigned long flags, const void *data) -{ - return syscall(__NR_mount, src, tgt, fst, flags, data); -} -static int sys_move_mount(int from_dfd, const char *from_pathname, - int to_dfd, const char *to_pathname, - unsigned int flags) -{ - return syscall(__NR_move_mount, from_dfd, from_pathname, to_dfd, to_pathname, flags); -} +#include "wrappers.h" static long get_file_dev_and_inode(void *addr, struct statx *stx) { diff --git a/tools/testing/selftests/filesystems/overlayfs/wrappers.h b/tools/testing/selftests/filesystems/overlayfs/wrappers.h new file mode 100644 index 0000000000000000000000000000000000000000..4f99e10f7f018fd9a7be5263f68d34807da4c53c --- /dev/null +++ b/tools/testing/selftests/filesystems/overlayfs/wrappers.h @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: GPL-2.0 +// +#ifndef __SELFTEST_OVERLAYFS_WRAPPERS_H__ +#define __SELFTEST_OVERLAYFS_WRAPPERS_H__ + +#define _GNU_SOURCE + +#include +#include +#include + +static inline int sys_fsopen(const char *fsname, unsigned int flags) +{ + return syscall(__NR_fsopen, fsname, flags); +} + +static inline int sys_fsconfig(int fd, unsigned int cmd, const char *key, + const char *value, int aux) +{ + return syscall(__NR_fsconfig, fd, cmd, key, value, aux); +} + +static inline int sys_fsmount(int fd, unsigned int flags, + unsigned int attr_flags) +{ + return syscall(__NR_fsmount, fd, flags, attr_flags); +} + +static inline int sys_mount(const char *src, const char *tgt, const char *fst, + unsigned long flags, const void *data) +{ + return syscall(__NR_mount, src, tgt, fst, flags, data); +} + +static inline int sys_move_mount(int from_dfd, const char *from_pathname, + int to_dfd, const char *to_pathname, + unsigned int flags) +{ + return syscall(__NR_move_mount, from_dfd, from_pathname, to_dfd, + to_pathname, flags); +} + +#endif From patchwork Mon Oct 14 09:41:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13834528 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C2A0157495; Mon, 14 Oct 2024 09:41:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728898876; cv=none; b=h4td4edVmbNeF4TarhbLbhlEKVLlZPQf/1lfWnvunBpMROnyN9FoE1tI+mDhCKvxSZzZbFPB6lZd+IEI3VgOSmIlBm1TkDYPpEG/tRltjmNsTYtVX4qF3wh3wkpz/t4f2eTR456oaB7yzkd9eM2DWS7buGiabuI4THyXl6XgdZg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728898876; c=relaxed/simple; bh=YE3nKWXbOHwrammoCXdDmbHesrdSCFRCRJKrflEt6Fc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bh2TwqrWUNW3eAKRe5x6V2Ls5Bdp67ibzWbYvTIyuZl9g8+h4bvyuR4C+ZzVcXHUBU9J1QQujpuwkVql0rDOYdwnTdkylwttw1EAdwSR58m1xVgLUtOoawBGXGsjYb1AUmbBwGvaZ80aBx8WcKbhG8hGNiM8+LK4+w55P/NBy8A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sSGcUw5W; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="sSGcUw5W" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0B94C4CED0; Mon, 14 Oct 2024 09:41:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728898876; bh=YE3nKWXbOHwrammoCXdDmbHesrdSCFRCRJKrflEt6Fc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=sSGcUw5WlR+5S40VMqG1HnlzvPhohIDR1r2JEU8NjOGTS4LiLQTXHwrATW5sJiv/u +ZF8SGkqVRMWpkItVlFqTOxFuqWqvcyCvubGXQbQTx42RQWxLy+xSsHhJtM8bCeE/F POKA2GnQ/3OCBnBNww7Kcv5S8rp/yCiiDpqpwd5iJ8rI+zzrYrpHg3ayoRs809wnWz dKZasH0uxQay7I/lKd/qA52F/TW6cSWaVpHVg/39tfaAHbG9k612sPHgADqwbneuxK LRFNWj4nFsQGkPjh8I4TbmojDxMhhInamHRRTEGAQKnDHJFX4Lz5ONi+Y9AUs7H6Tn IPlbvREf4PuTw== From: Christian Brauner Date: Mon, 14 Oct 2024 11:41:00 +0200 Subject: [PATCH v3 5/5] selftests: add overlayfs fd mounting selftests Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241014-work-overlayfs-v3-5-32b3fed1286e@kernel.org> References: <20241014-work-overlayfs-v3-0-32b3fed1286e@kernel.org> In-Reply-To: <20241014-work-overlayfs-v3-0-32b3fed1286e@kernel.org> To: Miklos Szeredi , Amir Goldstein Cc: Josef Bacik , linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org, Christian Brauner X-Mailer: b4 0.15-dev-2a633 X-Developer-Signature: v=1; a=openpgp-sha256; l=7648; i=brauner@kernel.org; h=from:subject:message-id; bh=YE3nKWXbOHwrammoCXdDmbHesrdSCFRCRJKrflEt6Fc=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaTzPDcM071b//RSdYr3mZt/zn2dIbm/ZpufnENOr+nu8 J5Xhdcfd5SyMIhxMciKKbI4tJuEyy3nqdhslKkBM4eVCWQIAxenAEzkNx8jw13JdXEGa4/vKi46 LnhUKMYyYf/KrHW5epdd7RgOTTxrlMzIsP6A8MHJrwLWif6SPmJ8+uy3hGvvRG49EklfM8VcuGz jMiYA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Signed-off-by: Christian Brauner --- .../selftests/filesystems/overlayfs/.gitignore | 1 + .../selftests/filesystems/overlayfs/Makefile | 2 +- .../filesystems/overlayfs/set_layers_via_fds.c | 152 +++++++++++++++++++++ .../selftests/filesystems/overlayfs/wrappers.h | 4 + 4 files changed, 158 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/filesystems/overlayfs/.gitignore b/tools/testing/selftests/filesystems/overlayfs/.gitignore index 52ae618fdd980ee22424d35d79f077077b132401..e23a18c8b37f2cdbb121496b1df1faffd729ad79 100644 --- a/tools/testing/selftests/filesystems/overlayfs/.gitignore +++ b/tools/testing/selftests/filesystems/overlayfs/.gitignore @@ -1,2 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-only dev_in_maps +set_layers_via_fds diff --git a/tools/testing/selftests/filesystems/overlayfs/Makefile b/tools/testing/selftests/filesystems/overlayfs/Makefile index 56b2b48a765b1d6706faee14616597ed0315f267..e8d1adb021af44588dd7af1049de66833bb584ce 100644 --- a/tools/testing/selftests/filesystems/overlayfs/Makefile +++ b/tools/testing/selftests/filesystems/overlayfs/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 -TEST_GEN_PROGS := dev_in_maps +TEST_GEN_PROGS := dev_in_maps set_layers_via_fds CFLAGS := -Wall -Werror diff --git a/tools/testing/selftests/filesystems/overlayfs/set_layers_via_fds.c b/tools/testing/selftests/filesystems/overlayfs/set_layers_via_fds.c new file mode 100644 index 0000000000000000000000000000000000000000..301fb5c02852e3ddff2f649b61c2833ce555df36 --- /dev/null +++ b/tools/testing/selftests/filesystems/overlayfs/set_layers_via_fds.c @@ -0,0 +1,152 @@ +// SPDX-License-Identifier: GPL-2.0 +#define _GNU_SOURCE +#define __SANE_USERSPACE_TYPES__ // Use ll64 + +#include +#include +#include +#include +#include +#include +#include + +#include "../../kselftest_harness.h" +#include "log.h" +#include "wrappers.h" + +FIXTURE(set_layers_via_fds) { +}; + +FIXTURE_SETUP(set_layers_via_fds) +{ + ASSERT_EQ(mkdir("/set_layers_via_fds", 0755), 0); +} + +FIXTURE_TEARDOWN(set_layers_via_fds) +{ + umount2("/set_layers_via_fds", 0); + ASSERT_EQ(rmdir("/set_layers_via_fds"), 0); +} + +TEST_F(set_layers_via_fds, set_layers_via_fds) +{ + int fd_context, fd_tmpfs, fd_overlay; + int layer_fds[] = { [0 ... 8] = -EBADF }; + bool layers_found[] = { [0 ... 8] = false }; + size_t len = 0; + char *line = NULL; + FILE *f_mountinfo; + + ASSERT_EQ(unshare(CLONE_NEWNS), 0); + ASSERT_EQ(sys_mount(NULL, "/", NULL, MS_SLAVE | MS_REC, NULL), 0); + + fd_context = sys_fsopen("tmpfs", 0); + ASSERT_GE(fd_context, 0); + + ASSERT_EQ(sys_fsconfig(fd_context, FSCONFIG_CMD_CREATE, NULL, NULL, 0), 0); + fd_tmpfs = sys_fsmount(fd_context, 0, 0); + ASSERT_GE(fd_tmpfs, 0); + ASSERT_EQ(close(fd_context), 0); + + ASSERT_EQ(mkdirat(fd_tmpfs, "w", 0755), 0); + ASSERT_EQ(mkdirat(fd_tmpfs, "u", 0755), 0); + ASSERT_EQ(mkdirat(fd_tmpfs, "l1", 0755), 0); + ASSERT_EQ(mkdirat(fd_tmpfs, "l2", 0755), 0); + ASSERT_EQ(mkdirat(fd_tmpfs, "l3", 0755), 0); + ASSERT_EQ(mkdirat(fd_tmpfs, "l4", 0755), 0); + ASSERT_EQ(mkdirat(fd_tmpfs, "d1", 0755), 0); + ASSERT_EQ(mkdirat(fd_tmpfs, "d2", 0755), 0); + ASSERT_EQ(mkdirat(fd_tmpfs, "d3", 0755), 0); + + layer_fds[0] = openat(fd_tmpfs, "w", O_DIRECTORY); + ASSERT_GE(layer_fds[0], 0); + + layer_fds[1] = openat(fd_tmpfs, "u", O_DIRECTORY); + ASSERT_GE(layer_fds[1], 0); + + layer_fds[2] = openat(fd_tmpfs, "l1", O_DIRECTORY); + ASSERT_GE(layer_fds[2], 0); + + layer_fds[3] = openat(fd_tmpfs, "l2", O_DIRECTORY); + ASSERT_GE(layer_fds[3], 0); + + layer_fds[4] = openat(fd_tmpfs, "l3", O_DIRECTORY); + ASSERT_GE(layer_fds[4], 0); + + layer_fds[5] = openat(fd_tmpfs, "l4", O_DIRECTORY); + ASSERT_GE(layer_fds[5], 0); + + layer_fds[6] = openat(fd_tmpfs, "d1", O_DIRECTORY); + ASSERT_GE(layer_fds[6], 0); + + layer_fds[7] = openat(fd_tmpfs, "d2", O_DIRECTORY); + ASSERT_GE(layer_fds[7], 0); + + layer_fds[8] = openat(fd_tmpfs, "d3", O_DIRECTORY); + ASSERT_GE(layer_fds[8], 0); + + ASSERT_EQ(sys_move_mount(fd_tmpfs, "", -EBADF, "/tmp", MOVE_MOUNT_F_EMPTY_PATH), 0); + ASSERT_EQ(close(fd_tmpfs), 0); + + fd_context = sys_fsopen("overlay", 0); + ASSERT_GE(fd_context, 0); + + ASSERT_NE(sys_fsconfig(fd_context, FSCONFIG_SET_FD, "lowerdir", NULL, layer_fds[2]), 0); + + ASSERT_EQ(sys_fsconfig(fd_context, FSCONFIG_SET_FD, "workdir", NULL, layer_fds[0]), 0); + ASSERT_EQ(sys_fsconfig(fd_context, FSCONFIG_SET_FD, "upperdir", NULL, layer_fds[1]), 0); + ASSERT_EQ(sys_fsconfig(fd_context, FSCONFIG_SET_FD, "lowerdir+", NULL, layer_fds[2]), 0); + ASSERT_EQ(sys_fsconfig(fd_context, FSCONFIG_SET_FD, "lowerdir+", NULL, layer_fds[3]), 0); + ASSERT_EQ(sys_fsconfig(fd_context, FSCONFIG_SET_FD, "lowerdir+", NULL, layer_fds[4]), 0); + ASSERT_EQ(sys_fsconfig(fd_context, FSCONFIG_SET_FD, "lowerdir+", NULL, layer_fds[5]), 0); + ASSERT_EQ(sys_fsconfig(fd_context, FSCONFIG_SET_FD, "datadir+", NULL, layer_fds[6]), 0); + ASSERT_EQ(sys_fsconfig(fd_context, FSCONFIG_SET_FD, "datadir+", NULL, layer_fds[7]), 0); + ASSERT_EQ(sys_fsconfig(fd_context, FSCONFIG_SET_FD, "datadir+", NULL, layer_fds[8]), 0); + + ASSERT_EQ(sys_fsconfig(fd_context, FSCONFIG_SET_STRING, "metacopy", "on", 0), 0); + + ASSERT_EQ(sys_fsconfig(fd_context, FSCONFIG_CMD_CREATE, NULL, NULL, 0), 0); + + fd_overlay = sys_fsmount(fd_context, 0, 0); + ASSERT_GE(fd_overlay, 0); + + ASSERT_EQ(sys_move_mount(fd_overlay, "", -EBADF, "/set_layers_via_fds", MOVE_MOUNT_F_EMPTY_PATH), 0); + + f_mountinfo = fopen("/proc/self/mountinfo", "r"); + ASSERT_NE(f_mountinfo, NULL); + + while (getline(&line, &len, f_mountinfo) != -1) { + char *haystack = line; + + if (strstr(haystack, "workdir=/tmp/w")) + layers_found[0] = true; + if (strstr(haystack, "upperdir=/tmp/u")) + layers_found[1] = true; + if (strstr(haystack, "lowerdir+=/tmp/l1")) + layers_found[2] = true; + if (strstr(haystack, "lowerdir+=/tmp/l2")) + layers_found[3] = true; + if (strstr(haystack, "lowerdir+=/tmp/l3")) + layers_found[4] = true; + if (strstr(haystack, "lowerdir+=/tmp/l4")) + layers_found[5] = true; + if (strstr(haystack, "datadir+=/tmp/d1")) + layers_found[6] = true; + if (strstr(haystack, "datadir+=/tmp/d2")) + layers_found[7] = true; + if (strstr(haystack, "datadir+=/tmp/d3")) + layers_found[8] = true; + } + free(line); + + for (int i = 0; i < ARRAY_SIZE(layer_fds); i++) { + ASSERT_EQ(layers_found[i], true); + ASSERT_EQ(close(layer_fds[i]), 0); + } + + ASSERT_EQ(close(fd_context), 0); + ASSERT_EQ(close(fd_overlay), 0); + ASSERT_EQ(fclose(f_mountinfo), 0); +} + +TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/filesystems/overlayfs/wrappers.h b/tools/testing/selftests/filesystems/overlayfs/wrappers.h index 4f99e10f7f018fd9a7be5263f68d34807da4c53c..071b95fd2ac0ad7b02d90e8e89df73fd27be69c3 100644 --- a/tools/testing/selftests/filesystems/overlayfs/wrappers.h +++ b/tools/testing/selftests/filesystems/overlayfs/wrappers.h @@ -32,6 +32,10 @@ static inline int sys_mount(const char *src, const char *tgt, const char *fst, return syscall(__NR_mount, src, tgt, fst, flags, data); } +#ifndef MOVE_MOUNT_F_EMPTY_PATH +#define MOVE_MOUNT_F_EMPTY_PATH 0x00000004 /* Empty from path permitted */ +#endif + static inline int sys_move_mount(int from_dfd, const char *from_pathname, int to_dfd, const char *to_pathname, unsigned int flags)