From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44045) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNqr4-0005ne-F3 for qemu-devel@nongnu.org; Tue, 17 Feb 2015 17:42:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YNqqz-0002JS-Ej for qemu-devel@nongnu.org; Tue, 17 Feb 2015 17:42:58 -0500 Received: from e7.ny.us.ibm.com ([32.97.182.137]:33720) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNqqz-0002JO-AM for qemu-devel@nongnu.org; Tue, 17 Feb 2015 17:42:53 -0500 Received: from /spool/local by e7.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 17 Feb 2015 17:42:53 -0500 Received: from b01cxnp23033.gho.pok.ibm.com (b01cxnp23033.gho.pok.ibm.com [9.57.198.28]) by d01dlp01.pok.ibm.com (Postfix) with ESMTP id 5F53838C8041 for ; Tue, 17 Feb 2015 17:39:06 -0500 (EST) Received: from d01av03.pok.ibm.com (d01av03.pok.ibm.com [9.56.224.217]) by b01cxnp23033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t1HMgnSL26607724 for ; Tue, 17 Feb 2015 22:42:49 GMT Received: from d01av03.pok.ibm.com (localhost [127.0.0.1]) by d01av03.pok.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t1HMgn1N016813 for ; Tue, 17 Feb 2015 17:42:49 -0500 From: Michael Roth Date: Tue, 17 Feb 2015 16:40:24 -0600 Message-Id: <1424212826-27606-9-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1424212826-27606-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1424212826-27606-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 08/10] qga: implement qmp_guest_get_memory_block_info() for Linux with sysfs List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, zhanghailiang From: zhanghailiang This conveys general information about guest memory blocks. Currently, just the memory block size. 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 *generalized guest-get-memory-block-size to get-get-memory-block-info for future extensibility Signed-off-by: Michael Roth --- qga/commands-posix.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 0fd5d95..6575c49 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -2266,8 +2266,35 @@ err: GuestMemoryBlockInfo *qmp_guest_get_memory_block_info(Error **errp) { - error_set(errp, QERR_UNSUPPORTED); - return NULL; + Error *local_err = NULL; + char *dirpath; + int dirfd; + char *buf; + GuestMemoryBlockInfo *info; + + 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 NULL; + } + 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 NULL; + } + + info = g_new0(GuestMemoryBlockInfo, 1); + info->size = strtol(buf, NULL, 16); /* the unit is bytes */ + + g_free(buf); + + return info; } #else /* defined(__linux__) */ -- 1.9.1