From nobody Sun Feb 8 23:25:50 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1580420628062770.0532455060459; Thu, 30 Jan 2020 13:43:48 -0800 (PST) Received: from localhost ([::1]:39552 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ixHbH-0002A5-01 for importer@patchew.org; Thu, 30 Jan 2020 16:43:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59218) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ixHWx-0003DH-LW for qemu-devel@nongnu.org; Thu, 30 Jan 2020 16:39:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ixHWw-0001N4-II for qemu-devel@nongnu.org; Thu, 30 Jan 2020 16:39:19 -0500 Received: from mail-qv1-xf42.google.com ([2607:f8b0:4864:20::f42]:34451) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ixHWw-0001LQ-E4; Thu, 30 Jan 2020 16:39:18 -0500 Received: by mail-qv1-xf42.google.com with SMTP id o18so2282227qvf.1; Thu, 30 Jan 2020 13:39:18 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:c177:887c:ce1b:6a44:15ec]) by smtp.gmail.com with ESMTPSA id f26sm3650597qtv.77.2020.01.30.13.39.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jan 2020 13:39:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=j3SBfARHb0Q5itXyfHtP6FdgEQPvIk7U2AMegh5GrHs=; b=srXJ75Nk0svSHAU/Lc0Ul5pfySABkeHQPg5gZPNdkvyb90NayJNDLpNIsPlaugjfNf OTPiqJztov018XNSHgfdYhhqr6ioOWyNIN3eaWOzq+geWlFdSq1Np80oEfuxfqxd0fha rn3Ae6eKj6wZ6ji8dSVekEw84D8GH1lqJIld0f4XEpZXj+aotwZinGHHokSMx0oCHNe6 Dh3qhIMoUCkOrc4Pb/LsZzaWeD8dCgbRP0XNc2ubq8sZ0zn6qEwtuvoY6vkbSzFCeW1v iwWauj5JtQRWSoRlz06Hx1UGnIW/IWCyfYDC5Q5lXESYkDTZYyvVbgzNPGKxDhkjl2sW j1HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=j3SBfARHb0Q5itXyfHtP6FdgEQPvIk7U2AMegh5GrHs=; b=aSzYk+Kt32B8yeEpckm+RPzC9FxE5mgGoQdDuZ/T9ZRGoWhxhm1qeCJIiWXh+hmv8J wOV0FVuuyqVy51bv11ulIPqWhR16RTqtyV3TjZjiTi9U42zLKlTHFzXyUcQYxnn+gYrf AYZqU+gZYc9kSeovrn6PjdFqdc3ub48cGjcae5hbBrZNW7XPJ3ygPANpk42wpeGDZvth XkpRPAtiWnp/PKAiCg/BgzA3xYwAi6J1hOaEbsigYganvPhwyAicSyMTsauLqGt5KYLI a3NTmoCqI23rS3gSh+dZcoRZx/5UpWHBOJ+f9fJYgjsqJZRSjKE94Vc0asX3I9vhoD1H 7kBg== X-Gm-Message-State: APjAAAWAeBfxNf8d9MMWFEb1ItffcXMMgTRiwz+Ohp2KyEydeZFTLHjQ l/3RGhhdcVqekNh9GchHg5e/CIIC X-Google-Smtp-Source: APXvYqx6h0Z5ta9VcTE8ux329Xhz1rLueajd+IDTv8KMHQJWhflQNYUOmKn5phWaswkgupv+yThMBg== X-Received: by 2002:a0c:ea92:: with SMTP id d18mr7006622qvp.201.1580420357635; Thu, 30 Jan 2020 13:39:17 -0800 (PST) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Subject: [PATCH v9 1/4] block: introducing 'bdrv_co_delete_file' interface Date: Thu, 30 Jan 2020 18:39:04 -0300 Message-Id: <20200130213907.2830642-2-danielhb413@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200130213907.2830642-1-danielhb413@gmail.com> References: <20200130213907.2830642-1-danielhb413@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::f42 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Daniel Henrique Barboza , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Adding to Block Drivers the capability of being able to clean up its created files can be useful in certain situations. For the LUKS driver, for instance, a failure in one of its authentication steps can leave files in the host that weren't there before. This patch adds the 'bdrv_co_delete_file' interface to block drivers and add it to the 'file' driver in file-posix.c. The implementation is given by 'raw_co_delete_file'. Suggested-by: Daniel P. Berrang=C3=A9 Signed-off-by: Daniel Henrique Barboza --- block/file-posix.c | 23 +++++++++++++++++++++++ include/block/block_int.h | 4 ++++ 2 files changed, 27 insertions(+) diff --git a/block/file-posix.c b/block/file-posix.c index 1b805bd938..ed28234bb8 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2386,6 +2386,28 @@ static int coroutine_fn raw_co_create_opts(const cha= r *filename, QemuOpts *opts, return raw_co_create(&options, errp); } =20 +static int coroutine_fn raw_co_delete_file(BlockDriverState *bs, + Error **errp) +{ + struct stat st; + int ret; + + if (!(stat(bs->filename, &st) =3D=3D 0) || !S_ISREG(st.st_mode)) { + error_setg_errno(errp, ENOENT, "%s is not a regular file", + bs->filename); + return -ENOENT; + } + + ret =3D unlink(bs->filename); + if (ret < 0) { + ret =3D -errno; + error_setg_errno(errp, -ret, "Error when deleting file %s", + bs->filename); + } + + return ret; +} + /* * Find allocation range in @bs around offset @start. * May change underlying file descriptor's file offset. @@ -3017,6 +3039,7 @@ BlockDriver bdrv_file =3D { .bdrv_co_block_status =3D raw_co_block_status, .bdrv_co_invalidate_cache =3D raw_co_invalidate_cache, .bdrv_co_pwrite_zeroes =3D raw_co_pwrite_zeroes, + .bdrv_co_delete_file =3D raw_co_delete_file, =20 .bdrv_co_preadv =3D raw_co_preadv, .bdrv_co_pwritev =3D raw_co_pwritev, diff --git a/include/block/block_int.h b/include/block/block_int.h index dd033d0b37..d938d3e8d2 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -314,6 +314,10 @@ struct BlockDriver { */ int coroutine_fn (*bdrv_co_flush)(BlockDriverState *bs); =20 + /* Delete a created file. */ + int coroutine_fn (*bdrv_co_delete_file)(BlockDriverState *bs, + Error **errp); + /* * Flushes all data that was already written to the OS all the way dow= n to * the disk (for example file-posix.c calls fsync()). --=20 2.24.1