From patchwork Thu Jan 22 02:40:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhanghailiang X-Patchwork-Id: 431659 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 6AD4A14029C for ; Thu, 22 Jan 2015 13:43:21 +1100 (AEDT) Received: from localhost ([::1]:50959 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YE7jr-00018b-9i for incoming@patchwork.ozlabs.org; Wed, 21 Jan 2015 21:43:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57787) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YE7hg-0005y6-GL for qemu-devel@nongnu.org; Wed, 21 Jan 2015 21:41:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YE7hY-0004S3-Mk for qemu-devel@nongnu.org; Wed, 21 Jan 2015 21:41:04 -0500 Received: from szxga02-in.huawei.com ([119.145.14.65]:17802) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YE7hY-0004Q8-2r for qemu-devel@nongnu.org; Wed, 21 Jan 2015 21:40:56 -0500 Received: from 172.24.2.119 (EHLO szxeml426-hub.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CGB32290; Thu, 22 Jan 2015 10:40:46 +0800 (CST) Received: from localhost (10.177.22.69) by szxeml426-hub.china.huawei.com (10.82.67.181) with Microsoft SMTP Server id 14.3.158.1; Thu, 22 Jan 2015 10:40:36 +0800 From: zhanghailiang To: Date: Thu, 22 Jan 2015 10:40:05 +0800 Message-ID: <1421894406-12180-5-git-send-email-zhang.zhanghailiang@huawei.com> X-Mailer: git-send-email 1.9.2.msysgit.0 In-Reply-To: <1421894406-12180-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1421894406-12180-1-git-send-email-zhang.zhanghailiang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.22.69] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 119.145.14.65 Cc: hangaohuai@huawei.com, zhanghailiang , peter.huangpeng@huawei.com, mdroth@linux.vnet.ibm.com, lcapitulino@redhat.com, lersek@redhat.com Subject: [Qemu-devel] [PATCH v2 4/5] qga: implement qmp_guest_get_memory_block_size() for Linux with sysfs 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 The size of a memory block is architecture dependent, it represents the logical unit upon which memory online/offline operations are to be performed. Signed-off-by: zhanghailiang --- qga/commands-posix.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 4b41385..44d9e8f 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -2147,8 +2147,33 @@ err: int64_t qmp_guest_get_memory_block_size(Error **errp) { - error_set(errp, QERR_UNSUPPORTED); - return -1; + Error *local_err = NULL; + char *dirpath; + int dirfd; + char *buf; + int64_t block_size; + + dirpath = g_strdup_printf("/sys/devices/system/memory/"); + dirfd = open(dirpath, O_RDONLY | O_DIRECTORY); + if (dirfd == -1) { + error_setg_errno(errp, errno, "open(\"%s\")", dirpath); + g_free(dirpath); + return -1; + } + g_free(dirpath); + + buf = g_malloc0(20); + ga_read_sysfs_file(dirfd, "block_size_bytes", buf, 20, &local_err); + if (local_err) { + g_free(buf); + error_propagate(errp, local_err); + return -1; + } + + block_size = strtol(buf, NULL, 16); /* the unit is bytes */ + g_free(buf); + + return block_size; } #else /* defined(__linux__) */