From patchwork Wed Jul 2 09:50:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chunyan Liu X-Patchwork-Id: 366307 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 34EE914009C for ; Wed, 2 Jul 2014 19:51:39 +1000 (EST) Received: from localhost ([::1]:52134 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X2HCT-0001Z7-8l for incoming@patchwork.ozlabs.org; Wed, 02 Jul 2014 05:51:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55485) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X2HC1-00013a-SQ for qemu-devel@nongnu.org; Wed, 02 Jul 2014 05:51:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X2HBv-0004uN-5R for qemu-devel@nongnu.org; Wed, 02 Jul 2014 05:51:09 -0400 Received: from victor.provo.novell.com ([137.65.250.26]:35443) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X2HBu-0004tw-Uq for qemu-devel@nongnu.org; Wed, 02 Jul 2014 05:51:03 -0400 Received: from linux-tt8j.lab.bej.apac.novell.com (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by victor.provo.novell.com with ESMTP (NOT encrypted); Wed, 02 Jul 2014 03:50:56 -0600 From: Chunyan Liu To: stefanha@redhat.com, qemu-devel@nongnu.org Date: Wed, 2 Jul 2014 17:50:40 +0800 Message-Id: <1404294640-16360-1-git-send-email-cyliu@suse.com> X-Mailer: git-send-email 1.8.4.5 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 137.65.250.26 Cc: Chunyan Liu Subject: [Qemu-devel] [PATCH] qemu-img info: show nocow info X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Add nocow info in 'qemu-img info' output to show whether the file currently has NOCOW flag set or not. Signed-off-by: Chunyan Liu --- block/qapi.c | 25 +++++++++++++++++++++++++ qapi/block-core.json | 3 ++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/block/qapi.c b/block/qapi.c index f44f6b4..d4dd5cc 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -28,6 +28,13 @@ #include "qapi-visit.h" #include "qapi/qmp-output-visitor.h" #include "qapi/qmp/types.h" +#ifdef __linux__ +#include +#include +#ifndef FS_NOCOW_FL +#define FS_NOCOW_FL 0x00800000 /* Do not cow file */ +#endif +#endif BlockDeviceInfo *bdrv_block_device_info(BlockDriverState *bs) { @@ -173,6 +180,20 @@ void bdrv_query_image_info(BlockDriverState *bs, Error *err = NULL; ImageInfo *info = g_new0(ImageInfo, 1); +#ifdef __linux__ + int fd, attr; + + /* get NOCOW info */ + fd = qemu_open(bs->filename, O_RDONLY | O_NONBLOCK); + if (fd >= 0) { + if (ioctl(fd, FS_IOC_GETFLAGS, &attr) == 0 && (attr & FS_NOCOW_FL)) { + info->has_nocow = true; + info->nocow = true; + } + qemu_close(fd); + } +#endif + bdrv_get_geometry(bs, &total_sectors); info->filename = g_strdup(bs->filename); @@ -625,4 +646,8 @@ void bdrv_image_info_dump(fprintf_function func_fprintf, void *f, func_fprintf(f, "Format specific information:\n"); bdrv_image_info_specific_dump(func_fprintf, f, info->format_specific); } + + if (info->has_nocow && info->nocow) { + func_fprintf(f, "no copy-on-write: yes\n"); + } } diff --git a/qapi/block-core.json b/qapi/block-core.json index e378653..b02c13c 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -126,7 +126,8 @@ '*backing-filename': 'str', '*full-backing-filename': 'str', '*backing-filename-format': 'str', '*snapshots': ['SnapshotInfo'], '*backing-image': 'ImageInfo', - '*format-specific': 'ImageInfoSpecific' } } + '*format-specific': 'ImageInfoSpecific', + '*nocow': 'bool' } } ## # @ImageCheck: