From patchwork Wed Aug 29 17:24:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Burri X-Patchwork-Id: 10580711 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2EAB65A4 for ; Wed, 29 Aug 2018 17:31:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 14FA52B8D5 for ; Wed, 29 Aug 2018 17:31:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 11AFF2B914; Wed, 29 Aug 2018 17:31:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF7652B8D5 for ; Wed, 29 Aug 2018 17:31:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727605AbeH2V3j (ORCPT ); Wed, 29 Aug 2018 17:29:39 -0400 Received: from tty0.vserver.softronics.ch ([91.214.169.36]:53536 "EHLO fe1.digint.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727460AbeH2V3j (ORCPT ); Wed, 29 Aug 2018 17:29:39 -0400 Received: by fe1.digint.ch (Postfix, from userid 1000) id E0E3D307E2; Wed, 29 Aug 2018 19:23:10 +0200 (CEST) Received: from mail.tty0.ch (hermes.tty0.ch [172.21.1.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by fe1.digint.ch (Postfix) with ESMTPS id 2A7B8307D2 for ; Wed, 29 Aug 2018 19:23:10 +0200 (CEST) Received: from ares.tty0.ch (ares.tty0.ch [10.0.1.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.tty0.ch (Postfix) with ESMTPS id 154CB1DA0EF; Wed, 29 Aug 2018 19:22:39 +0200 (CEST) Received: by ares.tty0.ch (sSMTP sendmail emulation); Wed, 29 Aug 2018 19:24:44 +0200 From: Axel Burri To: linux-btrfs@vger.kernel.org Cc: Axel Burri Subject: [RFC PATCH 1/6] btrfs-progs: splitcmd-gen.sh: create btrfs- binaries for selected subcommands Date: Wed, 29 Aug 2018 19:24:04 +0200 Message-Id: <20180829172409.18064-2-axel@tty0.ch> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180829172409.18064-1-axel@tty0.ch> References: <20180829172409.18064-1-axel@tty0.ch> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Create separate binaries for each subcommand ("btrfs foo bar"). Least invasive approach, generate c-files for each command: # ./splitcmd-gen.sh # make V=1 btrfs-subvolume-show # make V=1 btrfs-send # [...] Alternative approach: instead of including the c-file, link with obj in Makefile, e.g.: btrfs_subvolume_show_objects = cmds-subvolume.o btrfs_send_objects = cmds-send.o [...] This implies adaptions in cmds-subvolume.c (and others): -static int cmd_filesystem_show(int argc, char **argv) +int cmd_filesystem_show(int argc, char **argv) If they are defined non-static, we could probably simplify further and add `-Wl,-eentry` flags (changing entry point from "main" to "entry"). With this, and if handle_command_group() was declared in some library instead of btrfs.c, we would get rid of generated files completely. Signed-off-by: Axel Burri --- splitcmd-gen.sh | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ splitcmd.c.in | 17 ++++++++++++++ 2 files changed, 87 insertions(+) create mode 100755 splitcmd-gen.sh create mode 100644 splitcmd.c.in diff --git a/splitcmd-gen.sh b/splitcmd-gen.sh new file mode 100755 index 00000000..4d2e0509 --- /dev/null +++ b/splitcmd-gen.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +# +# Generate c-files for btrfs subcommands defined below +# + +# Notes on linux capabilities: +# +# btrfs-subvolume-show, btrfs-subvolume-list, btrfs-send: +# - CAP_FOWNER is only needed for O_NOATIME flag in open() system calls +# - why CAP_SYS_ADMIN? shouldn't CAP_DAC_READ_SEARCH be enough? +# +# btrfs-receive: +# - dependent on send-stream (see cmds-receive.c: "send_ops"): +# CAP_CHOWN, CAP_MKNOD, CAP_SETFCAP (for "lsetxattr") +# +# btrfs-filesystem-usage: +# - CAP_SYS_ADMIN is for BTRFS_IOC_TREE_SEARCH and BTRFS_IOC_FS_INFO +# in order to provide full level of detail, see btrfs-filesystem(8) + + +makefile_out="Makefile.install_setcap" + +splitcmd_list="" +setcap_lines="" + +function gen_splitcmd { + local name="$1" + local dest="${1}.c" + local cfile="$2" + local entry="$3" + local caps="$4" + echo "generating: ${dest} (cfile=${cfile}, entry=${entry})" + echo -e "/*\n * ${name}\n *\n * GENERATED BY splitcmd-gen.sh\n */\n" > $dest + sed -e "s|@BTRFS_SPLITCMD_CFILE_INCLUDE@|${cfile}|g" \ + -e "s|@BTRFS_SPLITCMD_ENTRY@|${entry}|g" \ + splitcmd.c.in >> $dest +} + +gen_splitcmd "btrfs-subvolume-show" \ + "cmds-subvolume.c" "cmd_subvol_show" \ + "cap_sys_admin,cap_fowner,cap_dac_read_search" + +gen_splitcmd "btrfs-subvolume-list" \ + "cmds-subvolume.c" "cmd_subvol_list" \ + "cap_sys_admin,cap_fowner,cap_dac_read_search" + +gen_splitcmd "btrfs-subvolume-snapshot" \ + "cmds-subvolume.c" "cmd_subvol_snapshot" \ + "cap_sys_admin,cap_fowner,cap_dac_override,cap_dac_read_search" + +gen_splitcmd "btrfs-subvolume-delete" \ + "cmds-subvolume.c" "cmd_subvol_delete" \ + "cap_sys_admin,cap_dac_override" + +gen_splitcmd "btrfs-send" \ + "cmds-send.c" "cmd_send" \ + "cap_sys_admin,cap_fowner,cap_dac_read_search" + +gen_splitcmd "btrfs-receive" \ + "cmds-receive.c" "cmd_receive" \ + "cap_sys_admin,cap_fowner,cap_chown,cap_mknod,cap_setfcap,cap_dac_override,cap_dac_read_search" + +gen_splitcmd "btrfs-filesystem-usage" \ + "cmds-fi-usage.c" "cmd_filesystem_usage" \ + "cap_sys_admin" + +gen_splitcmd "btrfs-qgroup-destroy" \ + "cmds-qgroup.c" "cmd_qgroup_destroy" \ + "cap_sys_admin,cap_dac_override" diff --git a/splitcmd.c.in b/splitcmd.c.in new file mode 100644 index 00000000..aa07af9a --- /dev/null +++ b/splitcmd.c.in @@ -0,0 +1,17 @@ +#include "@BTRFS_SPLITCMD_CFILE_INCLUDE@" + +/* + * Dummy object: used from second-level command groups (e.g. in + * "cmds-subvolume.c"), is never called in splitcmd executables. + */ +int handle_command_group(const struct cmd_group *grp, int argc, + char **argv) +{ + exit(1); +} + + +int main(int argc, char **argv) +{ + return @BTRFS_SPLITCMD_ENTRY@(argc, argv); +} From patchwork Wed Aug 29 17:24:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Burri X-Patchwork-Id: 10580707 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 065EA17DE for ; Wed, 29 Aug 2018 17:31:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D31352B891 for ; Wed, 29 Aug 2018 17:31:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D066F2B90A; Wed, 29 Aug 2018 17:31:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D4BD2B8F9 for ; Wed, 29 Aug 2018 17:31:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727818AbeH2V3k (ORCPT ); Wed, 29 Aug 2018 17:29:40 -0400 Received: from tty0.vserver.softronics.ch ([91.214.169.36]:53534 "EHLO fe1.digint.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727428AbeH2V3j (ORCPT ); Wed, 29 Aug 2018 17:29:39 -0400 Received: by fe1.digint.ch (Postfix, from userid 1000) id E8703307E6; Wed, 29 Aug 2018 19:23:11 +0200 (CEST) Received: from mail.tty0.ch (hermes.tty0.ch [172.21.1.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by fe1.digint.ch (Postfix) with ESMTPS id 38641307DF for ; Wed, 29 Aug 2018 19:23:11 +0200 (CEST) Received: from ares.tty0.ch (ares.tty0.ch [10.0.1.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.tty0.ch (Postfix) with ESMTPS id 22CC11DA0F0; Wed, 29 Aug 2018 19:22:40 +0200 (CEST) Received: by ares.tty0.ch (sSMTP sendmail emulation); Wed, 29 Aug 2018 19:24:45 +0200 From: Axel Burri To: linux-btrfs@vger.kernel.org Cc: Axel Burri Subject: [RFC PATCH 2/6] btrfs-progs: add btrfs- source files generated by splitcmd-gen.sh Date: Wed, 29 Aug 2018 19:24:05 +0200 Message-Id: <20180829172409.18064-3-axel@tty0.ch> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180829172409.18064-1-axel@tty0.ch> References: <20180829172409.18064-1-axel@tty0.ch> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Another approach would be to generate the splitted commands in the Makefile on-demand, which is probably not desired. Signed-off-by: Axel Burri --- btrfs-filesystem-usage.c | 23 +++++++++++++++++++++++ btrfs-qgroup-destroy.c | 23 +++++++++++++++++++++++ btrfs-receive.c | 23 +++++++++++++++++++++++ btrfs-send.c | 23 +++++++++++++++++++++++ btrfs-subvolume-delete.c | 23 +++++++++++++++++++++++ btrfs-subvolume-list.c | 23 +++++++++++++++++++++++ btrfs-subvolume-show.c | 23 +++++++++++++++++++++++ btrfs-subvolume-snapshot.c | 23 +++++++++++++++++++++++ 8 files changed, 184 insertions(+) create mode 100644 btrfs-filesystem-usage.c create mode 100644 btrfs-qgroup-destroy.c create mode 100644 btrfs-receive.c create mode 100644 btrfs-send.c create mode 100644 btrfs-subvolume-delete.c create mode 100644 btrfs-subvolume-list.c create mode 100644 btrfs-subvolume-show.c create mode 100644 btrfs-subvolume-snapshot.c diff --git a/btrfs-filesystem-usage.c b/btrfs-filesystem-usage.c new file mode 100644 index 00000000..e102ebc8 --- /dev/null +++ b/btrfs-filesystem-usage.c @@ -0,0 +1,23 @@ +/* + * btrfs-filesystem-usage + * + * GENERATED BY splitcmd-gen.sh + */ + +#include "cmds-fi-usage.c" + +/* + * Dummy object: used from second-level command groups (e.g. in + * "cmds-subvolume.c"), is never called in splitcmd executables. + */ +int handle_command_group(const struct cmd_group *grp, int argc, + char **argv) +{ + exit(1); +} + + +int main(int argc, char **argv) +{ + return cmd_filesystem_usage(argc, argv); +} diff --git a/btrfs-qgroup-destroy.c b/btrfs-qgroup-destroy.c new file mode 100644 index 00000000..4fb32210 --- /dev/null +++ b/btrfs-qgroup-destroy.c @@ -0,0 +1,23 @@ +/* + * btrfs-qgroup-destroy + * + * GENERATED BY splitcmd-gen.sh + */ + +#include "cmds-qgroup.c" + +/* + * Dummy object: used from second-level command groups (e.g. in + * "cmds-subvolume.c"), is never called in splitcmd executables. + */ +int handle_command_group(const struct cmd_group *grp, int argc, + char **argv) +{ + exit(1); +} + + +int main(int argc, char **argv) +{ + return cmd_qgroup_destroy(argc, argv); +} diff --git a/btrfs-receive.c b/btrfs-receive.c new file mode 100644 index 00000000..9fe94080 --- /dev/null +++ b/btrfs-receive.c @@ -0,0 +1,23 @@ +/* + * btrfs-receive + * + * GENERATED BY splitcmd-gen.sh + */ + +#include "cmds-receive.c" + +/* + * Dummy object: used from second-level command groups (e.g. in + * "cmds-subvolume.c"), is never called in splitcmd executables. + */ +int handle_command_group(const struct cmd_group *grp, int argc, + char **argv) +{ + exit(1); +} + + +int main(int argc, char **argv) +{ + return cmd_receive(argc, argv); +} diff --git a/btrfs-send.c b/btrfs-send.c new file mode 100644 index 00000000..0eff2931 --- /dev/null +++ b/btrfs-send.c @@ -0,0 +1,23 @@ +/* + * btrfs-send + * + * GENERATED BY splitcmd-gen.sh + */ + +#include "cmds-send.c" + +/* + * Dummy object: used from second-level command groups (e.g. in + * "cmds-subvolume.c"), is never called in splitcmd executables. + */ +int handle_command_group(const struct cmd_group *grp, int argc, + char **argv) +{ + exit(1); +} + + +int main(int argc, char **argv) +{ + return cmd_send(argc, argv); +} diff --git a/btrfs-subvolume-delete.c b/btrfs-subvolume-delete.c new file mode 100644 index 00000000..d6018d8b --- /dev/null +++ b/btrfs-subvolume-delete.c @@ -0,0 +1,23 @@ +/* + * btrfs-subvolume-delete + * + * GENERATED BY splitcmd-gen.sh + */ + +#include "cmds-subvolume.c" + +/* + * Dummy object: used from second-level command groups (e.g. in + * "cmds-subvolume.c"), is never called in splitcmd executables. + */ +int handle_command_group(const struct cmd_group *grp, int argc, + char **argv) +{ + exit(1); +} + + +int main(int argc, char **argv) +{ + return cmd_subvol_delete(argc, argv); +} diff --git a/btrfs-subvolume-list.c b/btrfs-subvolume-list.c new file mode 100644 index 00000000..8529aef5 --- /dev/null +++ b/btrfs-subvolume-list.c @@ -0,0 +1,23 @@ +/* + * btrfs-subvolume-list + * + * GENERATED BY splitcmd-gen.sh + */ + +#include "cmds-subvolume.c" + +/* + * Dummy object: used from second-level command groups (e.g. in + * "cmds-subvolume.c"), is never called in splitcmd executables. + */ +int handle_command_group(const struct cmd_group *grp, int argc, + char **argv) +{ + exit(1); +} + + +int main(int argc, char **argv) +{ + return cmd_subvol_list(argc, argv); +} diff --git a/btrfs-subvolume-show.c b/btrfs-subvolume-show.c new file mode 100644 index 00000000..856f97cf --- /dev/null +++ b/btrfs-subvolume-show.c @@ -0,0 +1,23 @@ +/* + * btrfs-subvolume-show + * + * GENERATED BY splitcmd-gen.sh + */ + +#include "cmds-subvolume.c" + +/* + * Dummy object: used from second-level command groups (e.g. in + * "cmds-subvolume.c"), is never called in splitcmd executables. + */ +int handle_command_group(const struct cmd_group *grp, int argc, + char **argv) +{ + exit(1); +} + + +int main(int argc, char **argv) +{ + return cmd_subvol_show(argc, argv); +} diff --git a/btrfs-subvolume-snapshot.c b/btrfs-subvolume-snapshot.c new file mode 100644 index 00000000..efdc0142 --- /dev/null +++ b/btrfs-subvolume-snapshot.c @@ -0,0 +1,23 @@ +/* + * btrfs-subvolume-snapshot + * + * GENERATED BY splitcmd-gen.sh + */ + +#include "cmds-subvolume.c" + +/* + * Dummy object: used from second-level command groups (e.g. in + * "cmds-subvolume.c"), is never called in splitcmd executables. + */ +int handle_command_group(const struct cmd_group *grp, int argc, + char **argv) +{ + exit(1); +} + + +int main(int argc, char **argv) +{ + return cmd_subvol_snapshot(argc, argv); +} From patchwork Wed Aug 29 17:24:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Burri X-Patchwork-Id: 10580717 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C1A98139B for ; Wed, 29 Aug 2018 17:31:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A32012B88A for ; Wed, 29 Aug 2018 17:31:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A13E92B880; Wed, 29 Aug 2018 17:31:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 70BA92B88A for ; Wed, 29 Aug 2018 17:31:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727661AbeH2V3k (ORCPT ); Wed, 29 Aug 2018 17:29:40 -0400 Received: from tty0.vserver.softronics.ch ([91.214.169.36]:53532 "EHLO fe1.digint.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727254AbeH2V3j (ORCPT ); Wed, 29 Aug 2018 17:29:39 -0400 X-Greylist: delayed 543 seconds by postgrey-1.27 at vger.kernel.org; Wed, 29 Aug 2018 17:29:38 EDT Received: by fe1.digint.ch (Postfix, from userid 1000) id DB293307E8; Wed, 29 Aug 2018 19:23:12 +0200 (CEST) Received: from mail.tty0.ch (hermes.tty0.ch [172.21.1.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by fe1.digint.ch (Postfix) with ESMTPS id 4798C307DF for ; Wed, 29 Aug 2018 19:23:12 +0200 (CEST) Received: from ares.tty0.ch (ares.tty0.ch [10.0.1.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.tty0.ch (Postfix) with ESMTPS id 3088B1DA0F1; Wed, 29 Aug 2018 19:22:41 +0200 (CEST) Received: by ares.tty0.ch (sSMTP sendmail emulation); Wed, 29 Aug 2018 19:24:46 +0200 From: Axel Burri To: linux-btrfs@vger.kernel.org Cc: Axel Burri Subject: [RFC PATCH 3/6] btrfs-progs: Makefile: add "install-splitcmd-setcap" target, installs splitcmd binaries with appropriate capabilities Date: Wed, 29 Aug 2018 19:24:06 +0200 Message-Id: <20180829172409.18064-4-axel@tty0.ch> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180829172409.18064-1-axel@tty0.ch> References: <20180829172409.18064-1-axel@tty0.ch> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Install all $progs_install_splitcmd, and set appropriate linux file capabilities(7) using setcap(8). NOTE: while installing, group is hardcoded to "btrfs"! This needs further discussion. Signed-off-by: Axel Burri --- Makefile | 36 ++++++++++++++++++++++++++++++++++++ Makefile.inc.in | 1 + configure.ac | 1 + 3 files changed, 38 insertions(+) diff --git a/Makefile b/Makefile index fcfc815a..5a1e2747 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ # static build static bnaries, requires static version of the libraries # test run the full testsuite # install install to default location (/usr/local) +# install-splitcmd-setcap install splitcmd binaries, and set linux capabilities # clean clean built binaries (not the documentation) # clean-all clean as above, clean docs and generated files # @@ -231,6 +232,30 @@ progs_install = progs_build = endif +# split-command executables, generated by splitcmd-gen.sh +progs_splitcmd = btrfs-send \ + btrfs-receive \ + btrfs-subvolume-list \ + btrfs-subvolume-show \ + btrfs-subvolume-snapshot \ + btrfs-subvolume-delete \ + btrfs-filesystem-usage \ + btrfs-qgroup-destroy + +progs_install_splitcmd = $(progs_splitcmd) + +INSTALL_SETCAP_FLAGS = -m710 -gbtrfs + +# linux capabilities(7) needed; used by "install-splitcmd-setcap-%" below +btrfs_subvolume_show_fcaps = "cap_sys_admin,cap_fowner,cap_dac_read_search" +btrfs_subvolume_list_fcaps = "cap_sys_admin,cap_fowner,cap_dac_read_search" +btrfs_subvolume_snapshot_fcaps = "cap_sys_admin,cap_fowner,cap_dac_override,cap_dac_read_search" +btrfs_subvolume_delete_fcaps = "cap_sys_admin,cap_dac_override" +btrfs_send_fcaps = "cap_sys_admin,cap_fowner,cap_dac_read_search" +btrfs_receive_fcaps = "cap_sys_admin,cap_fowner,cap_chown,cap_mknod,cap_setfcap,cap_dac_override,cap_dac_read_search" +btrfs_filesystem_usage_fcaps = "cap_sys_admin" +btrfs_qgroup_destroy_fcaps = "cap_sys_admin,cap_dac_override" + # external libs required by various binaries; for btrfs-foo, # specify btrfs_foo_libs = ; see $($(subst...)) rules below btrfs_convert_cflags = -DBTRFSCONVERT_EXT2=$(BTRFSCONVERT_EXT2) @@ -318,6 +343,7 @@ endif $($(subst -,_,btrfs-$(@:%/$(notdir $@)=%)-cflags)) all: $(progs_build) $(libs_build) $(BUILDDIRS) +splitcmd: $(progs_splitcmd) ifeq ($(PYTHON_BINDINGS),1) all: libbtrfsutil_python endif @@ -618,6 +644,7 @@ clean: $(CLEANDIRS) $(check_defs) \ $(libs) $(lib_links) \ $(progs_static) \ + $(progs_splitcmd) \ libbtrfsutil/*.o libbtrfsutil/*.o.d ifeq ($(PYTHON_BINDINGS),1) $(Q)cd libbtrfsutil/python; \ @@ -678,6 +705,15 @@ install-static: $(progs_static) $(INSTALLDIRS) # btrfsck is a link to btrfs in the src tree, make it so for installed file as well $(LN_S) -f btrfs.static $(DESTDIR)$(bindir)/btrfsck.static +# install split-command binary, and set linux capabilities(7) defined +# in btrfs_*_fcaps above, using setcap(8) +install-splitcmd-setcap-%: % + @echo $(INSTALL) -m755 -d $(DESTDIR)$(bindir) + @echo $(INSTALL) $(INSTALL_SETCAP_FLAGS) $< $(DESTDIR)$(bindir) + @echo $(SETCAP) $($(subst -,_,$<)_fcaps)+ep $(DESTDIR)$(bindir)/$< + +install-splitcmd-setcap: $(progs_install_splitcmd) $(patsubst %,install-splitcmd-setcap-%,$(progs_install_splitcmd)) + $(INSTALLDIRS): @echo "Making install in $(patsubst install-%,%,$@)" $(Q)$(MAKE) $(MAKEOPTS) -C $(patsubst install-%,%,$@) install diff --git a/Makefile.inc.in b/Makefile.inc.in index a86c528e..567e4e6f 100644 --- a/Makefile.inc.in +++ b/Makefile.inc.in @@ -10,6 +10,7 @@ AR = @AR@ RM = @RM@ RMDIR = @RMDIR@ INSTALL = @INSTALL@ +SETCAP = @SETCAP@ DISABLE_DOCUMENTATION = @DISABLE_DOCUMENTATION@ DISABLE_BTRFSCONVERT = @DISABLE_BTRFSCONVERT@ BUILD_PROGRAMS = @BUILD_PROGRAMS@ diff --git a/configure.ac b/configure.ac index df02f206..fefbfd9c 100644 --- a/configure.ac +++ b/configure.ac @@ -39,6 +39,7 @@ AC_PROG_LN_S AC_CHECK_TOOL([AR], [ar]) AC_PATH_PROG([RM], [rm], [rm]) AC_PATH_PROG([RMDIR], [rmdir], [rmdir]) +AC_PATH_PROG([SETCAP], [setcap], [setcap]) AC_CHECK_FUNCS([openat], [], From patchwork Wed Aug 29 17:24:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Burri X-Patchwork-Id: 10580709 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1AAB5180E for ; Wed, 29 Aug 2018 17:31:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0188C2B918 for ; Wed, 29 Aug 2018 17:31:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F287F2B85F; Wed, 29 Aug 2018 17:31:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0CC6E2B8AC for ; Wed, 29 Aug 2018 17:31:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727698AbeH2V3k (ORCPT ); Wed, 29 Aug 2018 17:29:40 -0400 Received: from tty0.vserver.softronics.ch ([91.214.169.36]:53530 "EHLO fe1.digint.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727477AbeH2V3j (ORCPT ); Wed, 29 Aug 2018 17:29:39 -0400 Received: by fe1.digint.ch (Postfix, from userid 1000) id A16A9307E9; Wed, 29 Aug 2018 19:23:13 +0200 (CEST) Received: from mail.tty0.ch (hermes.tty0.ch [172.21.1.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by fe1.digint.ch (Postfix) with ESMTPS id 53415307DF for ; Wed, 29 Aug 2018 19:23:13 +0200 (CEST) Received: from ares.tty0.ch (ares.tty0.ch [10.0.1.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.tty0.ch (Postfix) with ESMTPS id 3DEA51DA0F2; Wed, 29 Aug 2018 19:22:42 +0200 (CEST) Received: by ares.tty0.ch (sSMTP sendmail emulation); Wed, 29 Aug 2018 19:24:47 +0200 From: Axel Burri To: linux-btrfs@vger.kernel.org Cc: Axel Burri Subject: [RFC PATCH 4/6] btrfs-progs: Makefile: include Makefile.install_setcap generated by splitcmd-gen.sh Date: Wed, 29 Aug 2018 19:24:07 +0200 Message-Id: <20180829172409.18064-5-axel@tty0.ch> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180829172409.18064-1-axel@tty0.ch> References: <20180829172409.18064-1-axel@tty0.ch> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Axel Burri --- Makefile | 11 ++--------- Makefile.install_setcap | 10 ++++++++++ splitcmd-gen.sh | 5 +++++ 3 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 Makefile.install_setcap diff --git a/Makefile b/Makefile index 5a1e2747..acf5a677 100644 --- a/Makefile +++ b/Makefile @@ -246,15 +246,8 @@ progs_install_splitcmd = $(progs_splitcmd) INSTALL_SETCAP_FLAGS = -m710 -gbtrfs -# linux capabilities(7) needed; used by "install-splitcmd-setcap-%" below -btrfs_subvolume_show_fcaps = "cap_sys_admin,cap_fowner,cap_dac_read_search" -btrfs_subvolume_list_fcaps = "cap_sys_admin,cap_fowner,cap_dac_read_search" -btrfs_subvolume_snapshot_fcaps = "cap_sys_admin,cap_fowner,cap_dac_override,cap_dac_read_search" -btrfs_subvolume_delete_fcaps = "cap_sys_admin,cap_dac_override" -btrfs_send_fcaps = "cap_sys_admin,cap_fowner,cap_dac_read_search" -btrfs_receive_fcaps = "cap_sys_admin,cap_fowner,cap_chown,cap_mknod,cap_setfcap,cap_dac_override,cap_dac_read_search" -btrfs_filesystem_usage_fcaps = "cap_sys_admin" -btrfs_qgroup_destroy_fcaps = "cap_sys_admin,cap_dac_override" +# defines btrfs_*_caps; used by "install-splitcmd-setcap-%" below +include Makefile.install_setcap # external libs required by various binaries; for btrfs-foo, # specify btrfs_foo_libs = ; see $($(subst...)) rules below diff --git a/Makefile.install_setcap b/Makefile.install_setcap new file mode 100644 index 00000000..7705db74 --- /dev/null +++ b/Makefile.install_setcap @@ -0,0 +1,10 @@ +# capabilities(7) for splitcmd executables + +btrfs_subvolume_show_fcaps = "cap_sys_admin,cap_fowner,cap_dac_read_search" +btrfs_subvolume_list_fcaps = "cap_sys_admin,cap_fowner,cap_dac_read_search" +btrfs_subvolume_snapshot_fcaps = "cap_sys_admin,cap_fowner,cap_dac_override,cap_dac_read_search" +btrfs_subvolume_delete_fcaps = "cap_sys_admin,cap_dac_override" +btrfs_send_fcaps = "cap_sys_admin,cap_fowner,cap_dac_read_search" +btrfs_receive_fcaps = "cap_sys_admin,cap_fowner,cap_chown,cap_mknod,cap_setfcap,cap_dac_override,cap_dac_read_search" +btrfs_filesystem_usage_fcaps = "cap_sys_admin" +btrfs_qgroup_destroy_fcaps = "cap_sys_admin,cap_dac_override" diff --git a/splitcmd-gen.sh b/splitcmd-gen.sh index 4d2e0509..d34c5cbd 100755 --- a/splitcmd-gen.sh +++ b/splitcmd-gen.sh @@ -35,8 +35,13 @@ function gen_splitcmd { sed -e "s|@BTRFS_SPLITCMD_CFILE_INCLUDE@|${cfile}|g" \ -e "s|@BTRFS_SPLITCMD_ENTRY@|${entry}|g" \ splitcmd.c.in >> $dest + + echo "${name//-/_}_fcaps = \"${caps}\"" >> $makefile_out } +echo "generating: ${makefile_out}" +echo -e "# capabilities(7) for splitcmd executables\n" > $makefile_out + gen_splitcmd "btrfs-subvolume-show" \ "cmds-subvolume.c" "cmd_subvol_show" \ "cap_sys_admin,cap_fowner,cap_dac_read_search" From patchwork Wed Aug 29 17:24:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Burri X-Patchwork-Id: 10580713 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 09D8E5A4 for ; Wed, 29 Aug 2018 17:31:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E189D2B6A9 for ; Wed, 29 Aug 2018 17:31:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DF8562B831; Wed, 29 Aug 2018 17:31:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 625492B8E2 for ; Wed, 29 Aug 2018 17:31:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727676AbeH2V3k (ORCPT ); Wed, 29 Aug 2018 17:29:40 -0400 Received: from tty0.vserver.softronics.ch ([91.214.169.36]:53538 "EHLO fe1.digint.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727508AbeH2V3j (ORCPT ); Wed, 29 Aug 2018 17:29:39 -0400 Received: by fe1.digint.ch (Postfix, from userid 1000) id B6625307EE; Wed, 29 Aug 2018 19:23:14 +0200 (CEST) Received: from mail.tty0.ch (hermes.tty0.ch [172.21.1.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by fe1.digint.ch (Postfix) with ESMTPS id 5FB25307EA for ; Wed, 29 Aug 2018 19:23:14 +0200 (CEST) Received: from ares.tty0.ch (ares.tty0.ch [10.0.1.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.tty0.ch (Postfix) with ESMTPS id 4B00D1DA0F3; Wed, 29 Aug 2018 19:22:43 +0200 (CEST) Received: by ares.tty0.ch (sSMTP sendmail emulation); Wed, 29 Aug 2018 19:24:48 +0200 From: Axel Burri To: linux-btrfs@vger.kernel.org Cc: Axel Burri Subject: [RFC PATCH 5/6] btrfs-progs: Makefile: move progs_splitcmd variable to Makefile.install_setcap Date: Wed, 29 Aug 2018 19:24:08 +0200 Message-Id: <20180829172409.18064-6-axel@tty0.ch> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180829172409.18064-1-axel@tty0.ch> References: <20180829172409.18064-1-axel@tty0.ch> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Axel Burri --- Makefile | 17 ++++------------- Makefile.install_setcap | 2 ++ splitcmd-gen.sh | 17 ++++++++++++++--- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index acf5a677..3f16434c 100644 --- a/Makefile +++ b/Makefile @@ -232,22 +232,13 @@ progs_install = progs_build = endif -# split-command executables, generated by splitcmd-gen.sh -progs_splitcmd = btrfs-send \ - btrfs-receive \ - btrfs-subvolume-list \ - btrfs-subvolume-show \ - btrfs-subvolume-snapshot \ - btrfs-subvolume-delete \ - btrfs-filesystem-usage \ - btrfs-qgroup-destroy - -progs_install_splitcmd = $(progs_splitcmd) +# defines "progs_splitcmd" as well as "btrfs_*_fcaps" variables +# used by "install-splitcmd-setcap-%" below +include Makefile.install_setcap INSTALL_SETCAP_FLAGS = -m710 -gbtrfs -# defines btrfs_*_caps; used by "install-splitcmd-setcap-%" below -include Makefile.install_setcap +progs_install_splitcmd = $(progs_splitcmd) # external libs required by various binaries; for btrfs-foo, # specify btrfs_foo_libs = ; see $($(subst...)) rules below diff --git a/Makefile.install_setcap b/Makefile.install_setcap index 7705db74..e1efb686 100644 --- a/Makefile.install_setcap +++ b/Makefile.install_setcap @@ -1,5 +1,7 @@ # capabilities(7) for splitcmd executables +progs_splitcmd = btrfs-subvolume-show btrfs-subvolume-list btrfs-subvolume-snapshot btrfs-subvolume-delete btrfs-send btrfs-receive btrfs-filesystem-usage btrfs-qgroup-destroy + btrfs_subvolume_show_fcaps = "cap_sys_admin,cap_fowner,cap_dac_read_search" btrfs_subvolume_list_fcaps = "cap_sys_admin,cap_fowner,cap_dac_read_search" btrfs_subvolume_snapshot_fcaps = "cap_sys_admin,cap_fowner,cap_dac_override,cap_dac_read_search" diff --git a/splitcmd-gen.sh b/splitcmd-gen.sh index d34c5cbd..7492594f 100755 --- a/splitcmd-gen.sh +++ b/splitcmd-gen.sh @@ -36,12 +36,14 @@ function gen_splitcmd { -e "s|@BTRFS_SPLITCMD_ENTRY@|${entry}|g" \ splitcmd.c.in >> $dest - echo "${name//-/_}_fcaps = \"${caps}\"" >> $makefile_out + splitcmd_list="${splitcmd_list} ${name}"; + setcap_lines="${setcap_lines}\n${name//-/_}_fcaps = \"${caps}\"" } -echo "generating: ${makefile_out}" -echo -e "# capabilities(7) for splitcmd executables\n" > $makefile_out +# +# generate c-files +# gen_splitcmd "btrfs-subvolume-show" \ "cmds-subvolume.c" "cmd_subvol_show" \ "cap_sys_admin,cap_fowner,cap_dac_read_search" @@ -73,3 +75,12 @@ gen_splitcmd "btrfs-filesystem-usage" \ gen_splitcmd "btrfs-qgroup-destroy" \ "cmds-qgroup.c" "cmd_qgroup_destroy" \ "cap_sys_admin,cap_dac_override" + + +# +# generate Makefile includes +# +echo "generating: ${makefile_out}" +echo -e "# capabilities(7) for splitcmd executables" > $makefile_out +echo -e "\nprogs_splitcmd =$splitcmd_list" >> $makefile_out +echo -e "${setcap_lines}" >> $makefile_out From patchwork Wed Aug 29 17:24:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Burri X-Patchwork-Id: 10580705 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D637E5A4 for ; Wed, 29 Aug 2018 17:31:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC7672B8F4 for ; Wed, 29 Aug 2018 17:31:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BA4272B8EE; Wed, 29 Aug 2018 17:31:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4EF282B8D4 for ; Wed, 29 Aug 2018 17:31:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727859AbeH2V3l (ORCPT ); Wed, 29 Aug 2018 17:29:41 -0400 Received: from tty0.vserver.softronics.ch ([91.214.169.36]:53540 "EHLO fe1.digint.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727460AbeH2V3k (ORCPT ); Wed, 29 Aug 2018 17:29:40 -0400 Received: by fe1.digint.ch (Postfix, from userid 1000) id 8FECC307EF; Wed, 29 Aug 2018 19:23:15 +0200 (CEST) Received: from mail.tty0.ch (hermes.tty0.ch [172.21.1.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by fe1.digint.ch (Postfix) with ESMTPS id 6F22D307EA for ; Wed, 29 Aug 2018 19:23:15 +0200 (CEST) Received: from ares.tty0.ch (ares.tty0.ch [10.0.1.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.tty0.ch (Postfix) with ESMTPS id 583521DA0F4; Wed, 29 Aug 2018 19:22:44 +0200 (CEST) Received: by ares.tty0.ch (sSMTP sendmail emulation); Wed, 29 Aug 2018 19:24:49 +0200 From: Axel Burri To: linux-btrfs@vger.kernel.org Cc: Axel Burri Subject: [RFC PATCH 6/6] btrfs-progs: add splitcmd binaries to gitignore Date: Wed, 29 Aug 2018 19:24:09 +0200 Message-Id: <20180829172409.18064-7-axel@tty0.ch> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180829172409.18064-1-axel@tty0.ch> References: <20180829172409.18064-1-axel@tty0.ch> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Axel Burri --- .gitignore | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.gitignore b/.gitignore index 144ebb3b..299019e0 100644 --- a/.gitignore +++ b/.gitignore @@ -42,6 +42,15 @@ library-test-static /fssum testsuite-id +btrfs-filesystem-usage +btrfs-qgroup-destroy +btrfs-receive +btrfs-send +btrfs-subvolume-delete +btrfs-subvolume-list +btrfs-subvolume-show +btrfs-subvolume-snapshot + /tests/*-tests-results.txt /tests/test-console.txt /tests/test.img