From nobody Wed Nov 12 03:40:44 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=1567519586; cv=none; d=zoho.com; s=zohoarc; b=l58WLOgK+f0RxN3ghxsA6THkaylEroms1Hc+0B8CQVckeghDfuaIBJ+e/lRhN8yqB1qDj8+dPBDzsQghdoWMoNk6Kk9LrIEgvENgcGYznEDQzjWjSZ+8JzsFR3CgY0fSuGCJL1GuidDWeQ/AWYkmo+7WA5B9j9lQ3PuEhaLpte0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567519586; 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=ISRFJIcsQHvny5ehyZ7g2NR+kYMFconvzKsY4Lpa5sc=; b=PVs84IW3DNMSDbz8Gdhj4P1QF5f+jcwa8ITK2L0cmCUs+7J48joEfWVbeccof85fdZXNv1laOb1jVMfudsk5BL/j5l3MF3Zki8OBM0PRDB8z/YVrOnFag5IWTkyztmL+sPGMkWCUKjUkj43mL1hEcaHrCDEn1mevEBsVZEBeT3o= 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 15675195868889.95191600022747; Tue, 3 Sep 2019 07:06:26 -0700 (PDT) Received: from localhost ([::1]:46708 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i59Rv-0004sJ-1J for importer@patchew.org; Tue, 03 Sep 2019 10:06:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33756) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i59JF-0003LP-9p for qemu-devel@nongnu.org; Tue, 03 Sep 2019 09:57:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i59JC-0005iW-4B for qemu-devel@nongnu.org; Tue, 03 Sep 2019 09:57:23 -0400 Received: from mail-qt1-x843.google.com ([2607:f8b0:4864:20::843]:42396) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i59JB-0005hd-E4 for qemu-devel@nongnu.org; Tue, 03 Sep 2019 09:57:21 -0400 Received: by mail-qt1-x843.google.com with SMTP id t12so19982133qtp.9 for ; Tue, 03 Sep 2019 06:57:19 -0700 (PDT) Received: from rekt.ibmuc.com ([2804:431:c7c7:5c9f:9471:e230:52b:8c93]) by smtp.gmail.com with ESMTPSA id k49sm9211158qtc.9.2019.09.03.06.57.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2019 06:57:18 -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=ISRFJIcsQHvny5ehyZ7g2NR+kYMFconvzKsY4Lpa5sc=; b=Iz53mL1nw0oDH9yJIX2czma0m3exIDaGGevWWE60ww58fd2dSF/ksVCYqMF0fx+SZZ sHJJPLBA/l4VU55Y9bJlIxtXxf9AZOp0ucwl3b64UvlsR58cJFhVik2qm5iahigvBGbk DTPtsPLF+uJHpJu8mtly99ezJ8NwSbAoXueaJRy49Z9XoIsOEfej7JAQXPP0H+rsIgOv rciKmnRjOrFuX7n/pO01349rqkXOBjR6+5vSa4uqlwcQQEBFP05cHd9bV3mSzBvK03+u LRZrNvo6Z3javk0XiHRmnkULoMcMMp1dGlg3IYcRSRUsTAbUpe61ZP3lUeLsmtQlTtTe G1vQ== 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=ISRFJIcsQHvny5ehyZ7g2NR+kYMFconvzKsY4Lpa5sc=; b=S9CfzeLOVkspEvU1bXO++UPBB/4p+R8Ap6Xlg5M1eSqIV8RVJ9IzJDWdjKUYFOsEW/ ZnTjovCTXIDjod91qJT7x0zEx34xYdYV+n+glqsUcecMgTvKf4owkdYzm28lUrsi38DB gONpK0hyz43AggYZ4OHDqtuOClr7p52sttp3d732e7out9n+A4imsVBy3y4TiLRvJHRM fNFFEUj6kZmzBVd7KT/w+XP06RDauJR+CFut38rPJoTawc8sP671l7HFzkmGLd4GT0OX nvSy4X5DjoF9YBmfgp5rI8Q0pc0S8i90kuZCG3SKVso2X1xjIsHYPKTUQSSwxbBEenL4 5RmA== X-Gm-Message-State: APjAAAWpTHqteHiMF8sLlVbh85vlcEkp7eLkuKUsl82UsArdfxhhaCOq ukWbj8BtjUUVYIwzxVqmqnvH8UuKfLg= X-Google-Smtp-Source: APXvYqz5Wqcfsq/racGGRHgWqMXUKS6/s6I9j4X7CICowQrOafsruN1JTs7jec3UbUnODbG7nMt49Q== X-Received: by 2002:ac8:6745:: with SMTP id n5mr30498619qtp.68.1567519038775; Tue, 03 Sep 2019 06:57:18 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Date: Tue, 3 Sep 2019 10:57:05 -0300 Message-Id: <20190903135708.21624-2-danielhb413@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190903135708.21624-1-danielhb413@gmail.com> References: <20190903135708.21624-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::843 Subject: [Qemu-devel] [PATCH v7 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 0422acdf1c..a959ec2d1e 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -314,6 +314,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