From mboxrd@z Thu Jan 1 00:00:00 1970 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 From: zhanghailiang Date: Thu, 22 Jan 2015 10:40:05 +0800 Message-ID: <1421894406-12180-5-git-send-email-zhang.zhanghailiang@huawei.com> 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 Content-Type: text/plain Subject: [Qemu-devel] [PATCH v2 4/5] qga: implement qmp_guest_get_memory_block_size() for Linux with sysfs List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: hangaohuai@huawei.com, zhanghailiang , peter.huangpeng@huawei.com, mdroth@linux.vnet.ibm.com, lcapitulino@redhat.com, lersek@redhat.com 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__) */ -- 1.7.12.4