From nobody Wed Nov 12 02:02:25 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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 (zoho.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 ARC-Seal: i=1; a=rsa-sha256; t=1567458003; cv=none; d=zoho.com; s=zohoarc; b=HfXwVPAskdoOZhiBnP9YVyBy1fppfaL0pJj4fY3uPUpDOkGkmcVGrHzG9Ki3KkDaa6r6sZFqF7gEZacrHENQyznh2qo8W6u75OVQ+BEtk74DsYmqC40xirHFguCPTaPOmVbDOqod1jD5fIRTByXi7YqHI0iB+dhbjtXLi6rvAHA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567458003; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=VSXNt8Kn3icnDHyUvJOBRa++l6851CYhlNFBcR1U6UQ=; b=DL6Kx0kCJWmyAgWtcPLaD1sgZEr97fX87V6GQf/A01IWzctB0b4hVraeReHeTRvkQ3qalJ7TKjhYNmB6EenUhimzeJOXenIt79Q+35laXaQAi/d8DKyvS44Uc6lRNBaPtXUmx10AMkhPr+K5T92FgQxTmBdSHEnpNKvipx/mB8E= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 156745800363943.16088822844313; Mon, 2 Sep 2019 14:00:03 -0700 (PDT) Received: from localhost ([::1]:39966 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i4tQd-0006kz-16 for importer@patchew.org; Mon, 02 Sep 2019 16:59:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33402) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i4tPb-0005pe-Qp for qemu-devel@nongnu.org; Mon, 02 Sep 2019 16:58:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i4tPa-0004Fc-PP for qemu-devel@nongnu.org; Mon, 02 Sep 2019 16:58:55 -0400 Received: from mail-qt1-x844.google.com ([2607:f8b0:4864:20::844]:43907) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i4tPa-0004EZ-L1 for qemu-devel@nongnu.org; Mon, 02 Sep 2019 16:58:54 -0400 Received: by mail-qt1-x844.google.com with SMTP id l22so4715029qtp.10 for ; Mon, 02 Sep 2019 13:58:54 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c6:9589:1351:c7eb:87b:c9d5]) by smtp.gmail.com with ESMTPSA id w80sm4604038qka.62.2019.09.02.13.58.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2019 13:58:53 -0700 (PDT) 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=VSXNt8Kn3icnDHyUvJOBRa++l6851CYhlNFBcR1U6UQ=; b=T8oZEohIrzAdd5PFQXwnFFz/IxZ4PpOwm7nxtbmXEb3mZsuYwU8aGee4iyHY4I7z/B wk2h9wQkUzbXjEvII9oeFmcbk6XGUXqxZ7cvAzD+2Kx1jpHBxiqK22giaGFeefdS6U7X RqyuaLhXPcl7pOpysNDtxlOTTjslA8j7FVJLLpvKuEZX8ZUg7mpi2KdVrz9chpaHvee6 rjn613l6EqwoKzO+MPB4XlZeYSMnWzX3j2Ux3I26Pjb56LnZS2jOsNuM91T4LIf37G1I z7blZKuTiRWcKHVtgWjM1nhxCbqLlFBtwP7uYGz6RPFKy6Kf3QfqFfcBwGZ9ncrNfAwV XuUg== 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=VSXNt8Kn3icnDHyUvJOBRa++l6851CYhlNFBcR1U6UQ=; b=qZAd0K1WY2iBfRo27XcVQmHxt+mTL1ByQuFzPzsrN1SCQqLie7I3Krx402FEE1ukFZ 4X9l3AmdST57c5JfQWvU05OMHdZ0I4dceWKvC1xo3znbU9RRvJqi40pUxAbDMCrcqXeX uQeEoEJRorvqvwVk6VE8TOydWBpKTCqHlwbgPzsTXQD+E6fh6lsJH0W6gPGkL4jtdCrB xXwvMcCOO7nm+DMvG/MPQnY2w5mPSG2eMQyaJJ1Dls0EC5F+4wlHUt3wM42ATfMAn13I CqmnEbHKnOWDvtMjTk1Aojang46aGHDTqKEINhdrjYAe3B6k85+VOkKIw/OAfbnGPJhs C00w== X-Gm-Message-State: APjAAAWH6w6cgRvWuREuqcSwWE9YTdc5ITkuq7DxiRFuPwnn4mmQCMJr dWAhfSAcGhljXElAXECLrdHpW/r9 X-Google-Smtp-Source: APXvYqxRIDM0dRA3cFdzCsAhfcEZcFNcE/CSRHie+LUQNxhNl/MbmwDvUCvJ/fiHpSvCnRiHPdHGNQ== X-Received: by 2002:ac8:6916:: with SMTP id e22mr29288521qtr.313.1567457933847; Mon, 02 Sep 2019 13:58:53 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Date: Mon, 2 Sep 2019 17:58:39 -0300 Message-Id: <20190902205842.1884-2-danielhb413@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190902205842.1884-1-danielhb413@gmail.com> References: <20190902205842.1884-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::844 Subject: [Qemu-devel] [PATCH v6 1/4] block: introducing 'bdrv_co_delete_file' interface 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, =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Daniel Henrique Barboza , jsnow@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 | 28 ++++++++++++++++++++++++++++ include/block/block_int.h | 6 ++++++ 2 files changed, 34 insertions(+) diff --git a/block/file-posix.c b/block/file-posix.c index fbeb0068db..52756de522 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2390,6 +2390,33 @@ static int coroutine_fn raw_co_create_opts(const cha= r *filename, QemuOpts *opts, return raw_co_create(&options, errp); } =20 +/** + * Co-routine function that erases a regular file. + */ +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)) { + ret =3D -ENOENT; + error_setg_errno(errp, -ret, "%s is not a regular file", + bs->filename); + goto done; + } + + ret =3D unlink(bs->filename); + if (ret < 0) { + ret =3D -errno; + error_setg_errno(errp, -ret, "Error when deleting file %s", + bs->filename); + } + +done: + return ret; +} + /* * Find allocation range in @bs around offset @start. * May change underlying file descriptor's file offset. @@ -2942,6 +2969,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 ceec8c2f56..1442c75e3c 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -308,6 +308,12 @@ struct BlockDriver { */ int coroutine_fn (*bdrv_co_flush)(BlockDriverState *bs); =20 + /* + * Delete a local 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.21.0