From patchwork Fri May 12 12:52:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 1780590 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::53c; helo=mail-ed1-x53c.google.com; envelope-from=swupdate+bncbcxploxj6ikrbaxn7cramgqenuejzgy@googlegroups.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20221208 header.b=DgYalAyZ; dkim-atps=neutral Received: from mail-ed1-x53c.google.com (mail-ed1-x53c.google.com [IPv6:2a00:1450:4864:20::53c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QHpZJ4Pyqz1yfq for ; Fri, 12 May 2023 22:52:22 +1000 (AEST) Received: by mail-ed1-x53c.google.com with SMTP id 4fb4d7f45d1cf-50bca29a1desf11078367a12.2 for ; Fri, 12 May 2023 05:52:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1683895939; cv=pass; d=google.com; s=arc-20160816; b=qlVuZjUxQu5D6ebb9L+0OrMNsAfGhXqqmF2erTC9urYml2C8XWOQtpYWHvo1YCnB0W yj+l3qWVBZ9wnVUWnCgjl/qJ/el7GxTbQQ53D2Yb5aqQh/GtA79wsHIfCkoB0dd2DHBx jyYbJrO5KoghOh3JRQuEptvdvPda0Zm06DWX6EpJoZu3sufI2tCcO5EGpShKR0U61vCJ sHqRumWiRJEdLBZYk79CDe1FF/siC0nZTOaYZvXpGz41eY0lNdb1KkmfZgBQmsduqwAk 3uZdvYuQIFRxHdiJaInOY5l8pcgBevES5CoRzrzfMsbzK6UCuuYh232coA7k02S9z3H9 2flA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=JxJBPJZXdrMvs3B2wNCf5klohheg6D2jpdQdSuHtmLw=; b=OBUImpcT78WLN18K8cCGpZ9zLA0FUH2yEkWa4t9XCJW+/f3q5aVnVlMpry/oDld/81 oNUDnBBYOmpztulRvJ5ES1bK1/R0koA6J2QntjmCTGszamSKvK3JOk+heKYJX9t61pBA o56IY263rEeQ3qgoxry4kpBrFFcYKV5vRKD51+gFXY1Xonp160i2hSvKmew/v28x6FGI rX0xg5apvDzJsRNbMpFbnYORT0rN9ur7DpudLf4Wna2urKpNBVTtKIZAInKM5Jo9Ftzt J2vRf4lAl7umNsPFBXadWe+0vGDr1q+Z2jYrBKLWs1vwTfUI7yYN8kwCYvp5BgFzki16 OCjg== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.10 is neither permitted nor denied by domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20221208; t=1683895939; x=1686487939; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:sender:from:to:cc:subject:date:message-id :reply-to; bh=JxJBPJZXdrMvs3B2wNCf5klohheg6D2jpdQdSuHtmLw=; b=DgYalAyZp+yN4/MC2PK+GBuMbLEN7FhQBormA6NnoT3CUYf8Hxxzang8xpxGz1qnfl movVoZGlUrCMiNPxiKHJLmAGMju4TeFUOGxuoTIiQ+4eFFS/wAOoHvvAs+6oVu8EF1GD htiWnTaOeRH9dPaarCjwVhYBh9gt/+dbV6NViuDko7zQHLqLN8L9d8S8xaITFvMRpSWS 7MM9wQBof9KLsaBdigsISwVv+tgIgMOReCbOJZf8aoBbjDXpp6rzDuuoW7byUQk1tppH ndc3i58tSiC2A6aRHNpVv8WOdT6mlZGC+gNcBbYZIsn71D335ClNtMqx+JgwilFVQjTa y1/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683895939; x=1686487939; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :x-beenthere:x-gm-message-state:sender:from:to:cc:subject:date :message-id:reply-to; bh=JxJBPJZXdrMvs3B2wNCf5klohheg6D2jpdQdSuHtmLw=; b=BZuwGFHc9bkqvoBcb9RVrqHhh0YuKJs3bm3dNA0/RiZVFQViBNEFMqn7lHng8nRkl3 /bxjcOQtLALhQo7X3gIa/FMzbLgQ8cDX4xzWUHQRhFy1zoTqsbwn6EIQ0IOH4RVezjq9 p6KOjQEpM+bLeLui3yD8ZCcU9dLPHCcAuQCzf8ngLtvC7ewi7AfB47R5hGdJdNnZQDSR 9MbHEzLXZoQHU21ZRieyROZzferYILTQKWsa2qf1ylqp50GyfrIYA0pEEUktMKhiCDFY uf9GyvtFcImIeA3YlE27xTJDgzPAdsGZn7J6zNB1ktZUH8cou6cMNA7HFemteliKlgL+ Tn8w== Sender: swupdate@googlegroups.com X-Gm-Message-State: AC+VfDyLx6vn7cnhBFCwCfOkLVZ6aF9enhyF3ytkack1EaFtdFEb4nLc xtnLLtEoft3V1X6DGhdpPTs= X-Google-Smtp-Source: ACHHUZ719EmlVQEdzsjd+eaTLAe4oYw4J05pdnGNOLcH5D4jYD2kybaevKSquydTV0YVaW3GovIfIQ== X-Received: by 2002:a50:d09d:0:b0:50b:c79d:5201 with SMTP id v29-20020a50d09d000000b0050bc79d5201mr8909497edd.6.1683895939389; Fri, 12 May 2023 05:52:19 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a05:6402:4d7:b0:50d:9cf2:645e with SMTP id n23-20020a05640204d700b0050d9cf2645els2881650edw.1.-pod-prod-05-eu; Fri, 12 May 2023 05:52:18 -0700 (PDT) X-Received: by 2002:a17:907:36c6:b0:94f:562b:2979 with SMTP id bj6-20020a17090736c600b0094f562b2979mr22025051ejc.31.1683895937971; Fri, 12 May 2023 05:52:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683895937; cv=none; d=google.com; s=arc-20160816; b=Lwye43J92w0oApoc0WjSD1TMhOCF32h1c8m5FqQ9GK1pSWUWBU3doQHrUrQt6/AiM2 ryFazm81n1Lf/qo3so7cQthfo/nVf2Azk0y17OGrB6L9tFU5q+M2STlyyBA+xFO4D2bb B9Lt/4aKuuPetYie6war0PZGYZwFFOFP+pxQFVfdHplQdyUC0dPT5P8tplbAeWS8AvEA UdTgD4JBXuoUxljtNkG37QmVGjOaMaeqkMo/hWEw5zYSKWHKC+q8wPLL1tXHVK8skWmr 2GhS4uTrTAkWA3X0qhNy/Iu2t4B2qanFnPFzlrtIWu70RdO8rMS982zihTz3GaZ3tlB9 VxPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=QH8SFp9Lux/gwKvAkRmIlDLD2dzDNg9pjVFVjIot/Fo=; b=CBTYhDucobc+zoNdazIkxz4XU7qp43UZEUVawvDFY9bM1+9cMohNKPD916AL50i0Do x5W+MhMmcBrMXIXS5934nwkJ/P0hmbez4qKL1pWH/4xb3WdH+SiCqs7H/AIrZ1Lm3Pst LZdbZGpbKGNxi+AEx8rH1HL/Jg1SP3HTC4+zlNs3XfUMAAwvcjN9rUu3tzVRJqX/aY01 tRITQlUF9+uAzpJN3e46UdrAFfPX90KQE4hTkDTvoYgUe+6uH5zau3OTH9cbs6SM8Sqy 5Gv3/mRV0cbalddACN/4GWSuQzTJX3LIo1Od9G+XsmZxEysqiK+MY7yAuVwx1akHWSIV XxxQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.10 is neither permitted nor denied by domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=denx.de Received: from mail-out.m-online.net (mail-out.m-online.net. [212.18.0.10]) by gmr-mx.google.com with ESMTPS id ci17-20020a170906c35100b00965600719e4si985116ejb.1.2023.05.12.05.52.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 May 2023 05:52:17 -0700 (PDT) Received-SPF: neutral (google.com: 212.18.0.10 is neither permitted nor denied by domain of sbabic@denx.de) client-ip=212.18.0.10; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 4QHpZ955Qtz1s953; Fri, 12 May 2023 14:52:17 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 4QHpZ94K75z1qqlS; Fri, 12 May 2023 14:52:17 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id 0wO8-Rscf2zT; Fri, 12 May 2023 14:52:16 +0200 (CEST) Received: from babic.homelinux.org (host-88-217-136-221.customer.m-online.net [88.217.136.221]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPS; Fri, 12 May 2023 14:52:16 +0200 (CEST) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id F0BDD4541370; Fri, 12 May 2023 14:52:15 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kr3iLhO-1GOH; Fri, 12 May 2023 14:52:13 +0200 (CEST) Received: from paperino.fritz.box (paperino.fritz.box [192.168.178.48]) by babic.homelinux.org (Postfix) with ESMTP id 38FA04541350; Fri, 12 May 2023 14:52:13 +0200 (CEST) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 2/2] handler: handler for operation on BTRFS Date: Fri, 12 May 2023 14:52:11 +0200 Message-Id: <20230512125211.160912-2-sbabic@denx.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230512125211.160912-1-sbabic@denx.de> References: <20230512125211.160912-1-sbabic@denx.de> MIME-Version: 1.0 X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 212.18.0.10 is neither permitted nor denied by domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=denx.de Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Add an handler that works as wrapper for libbtrfsutil and add support to sw-description. Creation / deletion of subvolumes are supported. Signed-off-by: Stefano Babic --- doc/source/handlers.rst | 27 +++++++++- handlers/Makefile | 1 + handlers/btrfs_handler.c | 105 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 handlers/btrfs_handler.c diff --git a/doc/source/handlers.rst b/doc/source/handlers.rst index 1ee09e0..06999e6 100644 --- a/doc/source/handlers.rst +++ b/doc/source/handlers.rst @@ -985,7 +985,8 @@ supported: | fstype | string | Optional filesystem type to be created on the | | | | partition. If no fstype key is given, no file | | | | will be created on the corresponding partition. | - | | | vfat / ext2 / ext3 /ext4 file system is supported | + | | | vfat / ext2 / ext3 /ext4 / btrfs | + | | | file system is supported | +-------------+----------+----------------------------------------------------+ | partuuid | string | The partition UUID (GPT only). If omitted, a UUID | | | | will be generated automatically. | @@ -1152,6 +1153,30 @@ found on the device. It is a partition handler and it runs before any image is i } }); +BTRFS Handler +------------- + +This handler is activated if support for BTRFS is on. It allows to created and delete subvolumes +during an update. + +:: + + partitions: ( + { + type = "btrfs"; + device = "/dev/loop0p1"; + + properties: { + command = < one of create" or "delete" > + path = ; + mount = "true" or missing; + } + }) + + +If `mount` is set, SWUpdate will mount the device and the path is appenden to the +mountpoint used with mount. If device is already mounted, path is the absolute path. + Delta Update Handler -------------------- diff --git a/handlers/Makefile b/handlers/Makefile index 847d59f..b5203f9 100644 --- a/handlers/Makefile +++ b/handlers/Makefile @@ -10,6 +10,7 @@ obj-y += dummy_handler.o chain_handler.o obj-$(CONFIG_ARCHIVE) += archive_handler.o obj-$(CONFIG_BOOTLOADERHANDLER) += boot_handler.o +obj-$(CONFIG_BTRFS_FILESYSTEM) += btrfs_handler.o obj-$(CONFIG_COPY) += copy_handler.o obj-$(CONFIG_CFI) += flash_handler.o obj-$(CONFIG_DELTA) += delta_handler.o delta_downloader.o zchunk_range.o diff --git a/handlers/btrfs_handler.c b/handlers/btrfs_handler.c new file mode 100644 index 0000000..517f753 --- /dev/null +++ b/handlers/btrfs_handler.c @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2023 + * Stefano Babic, DENX Software Engineering, sbabic@denx.de. + * + * SPDX-License-Identifier: GPL-2.0-only + */ + +#include +#include +#include +#include +#include +#include "fs_interface.h" +#include "progress.h" +#include "swupdate_image.h" +#include "handler.h" + +typedef enum { + BTRFS_UNKNOWN, + BTRFS_CREATE_SUBVOLUME, + BTRFS_DELETE_SUBVOLUME +} btrfs_op_t; + +void btrfs_handler(void); + +static int btrfs(struct img_type *img, + void __attribute__ ((__unused__)) *data) +{ + int ret = 0; + btrfs_op_t op; + enum btrfs_util_error btrfs_error; + + char *subvol_path = dict_get_value(&img->properties, "path"); + char *cmd = dict_get_value(&img->properties, "command"); + char *globalpath; + char *mountpoint; + + op = IS_STR_EQUAL(cmd, "create") ? BTRFS_CREATE_SUBVOLUME : + IS_STR_EQUAL(cmd, "delete") ? BTRFS_DELETE_SUBVOLUME : BTRFS_UNKNOWN; + + if (op == BTRFS_UNKNOWN) { + ERROR("Wrong operation of btrfs filesystem: %s", cmd); + return -EINVAL; + } + bool tomount = IS_STR_EQUAL(dict_get_value(&img->properties, "mount"), "true"); + if (tomount) { + if (!strlen(img->device)) { + ERROR("btrfs must be mounted, no device set"); + return -EINVAL; + } + globalpath = alloca(strlen(get_tmpdir()) + + strlen(DATADST_DIR_SUFFIX) + strlen(subvol_path) + 2); + sprintf(globalpath, "%s%s", get_tmpdir(), DATADST_DIR_SUFFIX); + mountpoint = strdupa(globalpath); + DEBUG("Try to mount %s as BTRFS", mountpoint); + ret = swupdate_mount(img->device, mountpoint, "btrfs"); + if (ret) { + ERROR("%s cannot be mounted with btrfs", img->device); + return -1; + } + globalpath = strcat(globalpath, subvol_path); + } else + globalpath = subvol_path; + + DEBUG("%s subvolume %s...", (op == BTRFS_CREATE_SUBVOLUME) ? "Creating" : "Deleting", subvol_path); + switch (op) { + case BTRFS_CREATE_SUBVOLUME: + btrfs_error = btrfs_util_create_subvolume(globalpath, 0, NULL, NULL); + break; + case BTRFS_DELETE_SUBVOLUME: + btrfs_error = btrfs_util_delete_subvolume(globalpath, BTRFS_UTIL_DELETE_SUBVOLUME_RECURSIVE); + break; + default: + btrfs_error = BTRFS_UTIL_ERROR_FS_INFO_FAILED; + break; + } + + if (btrfs_error != BTRFS_UTIL_OK) { + ERROR("BTRFS %s failed with btrfs error : %s", cmd, + btrfs_util_strerror(btrfs_error)); + ret = -1; + } + + if (tomount) { + /* + * btrfs needs some time after creating a subvolume, + * so just delay here + */ + sleep(1); + swupdate_umount(mountpoint); + } + /* + * Declare that handler has finished + */ + swupdate_progress_update(100); + + return ret; +} + +__attribute__((constructor)) +void btrfs_handler(void) +{ + register_handler("btrfs", btrfs, + PARTITION_HANDLER | NO_DATA_HANDLER, NULL); +}