From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52372) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNYem-0007JU-BD for qemu-devel@nongnu.org; Mon, 16 Feb 2015 22:17:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YNYei-00054q-TH for qemu-devel@nongnu.org; Mon, 16 Feb 2015 22:17:04 -0500 Received: from e7.ny.us.ibm.com ([32.97.182.137]:33062) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YNYei-00054m-Or for qemu-devel@nongnu.org; Mon, 16 Feb 2015 22:17:00 -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 ; Mon, 16 Feb 2015 22:17:00 -0500 Received: from b01cxnp22034.gho.pok.ibm.com (b01cxnp22034.gho.pok.ibm.com [9.57.198.24]) by d01dlp02.pok.ibm.com (Postfix) with ESMTP id 7224D6E8040 for ; Mon, 16 Feb 2015 22:08:50 -0500 (EST) Received: from d01av05.pok.ibm.com (d01av05.pok.ibm.com [9.56.224.195]) by b01cxnp22034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t1H3GoXY27394222 for ; Tue, 17 Feb 2015 03:16:58 GMT Received: from d01av05.pok.ibm.com (localhost [127.0.0.1]) by d01av05.pok.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t1H3GPXv019510 for ; Mon, 16 Feb 2015 22:16:26 -0500 From: Michael Roth Date: Mon, 16 Feb 2015 21:14:50 -0600 Message-Id: <1424142892-7275-9-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1424142892-7275-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1424142892-7275-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 08/10] 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: peter.maydell@linaro.org, zhanghailiang From: zhanghailiang 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 Signed-off-by: Michael Roth --- 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 1c8080f..d8d7425 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -2267,8 +2267,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.9.1