diff mbox

[RFC,for-2.3,5/6] qga: implement qmp_guest_get_memory_block_size() for Linux with sysfs

Message ID 1417849159-6568-6-git-send-email-zhang.zhanghailiang@huawei.com
State New
Headers show

Commit Message

Zhanghailiang Dec. 6, 2014, 6:59 a.m. UTC
The size of a memory block is architecture dependent,
For example, power uses 16MiB, ia64 uses 1GiB, x86 uses 128M.
It represents the logical unit upon which memory online/offline operations are
to be performed.

This function will return the value to host user.

Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
---
 qga/commands-posix.c | 43 +++++++++++++++++++++++++++++++++++++------
 1 file changed, 37 insertions(+), 6 deletions(-)

Comments

Michael Roth Dec. 21, 2014, 9:41 p.m. UTC | #1
Quoting zhanghailiang (2014-12-06 00:59:18)
> The size of a memory block is architecture dependent,
> For example, power uses 16MiB, ia64 uses 1GiB, x86 uses 128M.

That's the minimum for Power, but the size can be set via device tree and
can differ from one platform to the next.

Should either clarify in the commit or maybe just drop the statement to
avoid confusion.

> It represents the logical unit upon which memory online/offline operations are
> to be performed.
> 
> This function will return the value to host user.
> 
> Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
> ---
>  qga/commands-posix.c | 43 +++++++++++++++++++++++++++++++++++++------
>  1 file changed, 37 insertions(+), 6 deletions(-)
> 
> diff --git a/qga/commands-posix.c b/qga/commands-posix.c
> index 1010e86..02c6b44 100644
> --- a/qga/commands-posix.c
> +++ b/qga/commands-posix.c
> @@ -2087,6 +2087,37 @@ int64_t qmp_guest_set_memory_blocks(GuestMemoryBlockList *mem_blks,
>      return processed;
>  }
> 
> +int64_t qmp_guest_get_memory_block_size(Error **errp)
> +{
> +    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__) */
> 
>  void qmp_guest_suspend_disk(Error **errp)
> @@ -2135,6 +2166,12 @@ int64_t qmp_guest_set_memory_blocks(GuestMemoryBlockList *mem_blks,
>      return -1;
>  }
> 
> +int64_t qmp_guest_get_memory_block_size(Error **errp)
> +{
> +    error_set(errp, QERR_UNSUPPORTED);
> +    return -1;
> +}
> +
>  #endif
> 
>  #if !defined(CONFIG_FSFREEZE)
> @@ -2221,12 +2258,6 @@ GList *ga_command_blacklist_init(GList *blacklist)
>      return blacklist;
>  }
> 
> -int64_t qmp_guest_get_memory_block_size(Error **errp)
> -{
> -    error_set(errp, QERR_UNSUPPORTED);
> -    return -1;
> -}
> -

Same as with above 2 patches, please squash into the initial stub patch

>  /* register init/cleanup routines for stateful command groups */
>  void ga_command_state_init(GAState *s, GACommandState *cs)
>  {
> -- 
> 1.7.12.4
Zhanghailiang Dec. 22, 2014, 10:21 a.m. UTC | #2
On 2014/12/22 5:41, Michael Roth wrote:
> Quoting zhanghailiang (2014-12-06 00:59:18)
>> The size of a memory block is architecture dependent,
>> For example, power uses 16MiB, ia64 uses 1GiB, x86 uses 128M.
>
> That's the minimum for Power, but the size can be set via device tree and
> can differ from one platform to the next.
>
> Should either clarify in the commit or maybe just drop the statement to
> avoid confusion.
>

OK, i will drop that statement.

>> It represents the logical unit upon which memory online/offline operations are
>> to be performed.
>>
>> This function will return the value to host user.
>>
>> Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
>> ---
>>   qga/commands-posix.c | 43 +++++++++++++++++++++++++++++++++++++------
>>   1 file changed, 37 insertions(+), 6 deletions(-)
>>
>> diff --git a/qga/commands-posix.c b/qga/commands-posix.c
>> index 1010e86..02c6b44 100644
>> --- a/qga/commands-posix.c
>> +++ b/qga/commands-posix.c
>> @@ -2087,6 +2087,37 @@ int64_t qmp_guest_set_memory_blocks(GuestMemoryBlockList *mem_blks,
>>       return processed;
>>   }
>>
>> +int64_t qmp_guest_get_memory_block_size(Error **errp)
>> +{
>> +    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__) */
>>
>>   void qmp_guest_suspend_disk(Error **errp)
>> @@ -2135,6 +2166,12 @@ int64_t qmp_guest_set_memory_blocks(GuestMemoryBlockList *mem_blks,
>>       return -1;
>>   }
>>
>> +int64_t qmp_guest_get_memory_block_size(Error **errp)
>> +{
>> +    error_set(errp, QERR_UNSUPPORTED);
>> +    return -1;
>> +}
>> +
>>   #endif
>>
>>   #if !defined(CONFIG_FSFREEZE)
>> @@ -2221,12 +2258,6 @@ GList *ga_command_blacklist_init(GList *blacklist)
>>       return blacklist;
>>   }
>>
>> -int64_t qmp_guest_get_memory_block_size(Error **errp)
>> -{
>> -    error_set(errp, QERR_UNSUPPORTED);
>> -    return -1;
>> -}
>> -
>
> Same as with above 2 patches, please squash into the initial stub patch
>

OK.

>>   /* register init/cleanup routines for stateful command groups */
>>   void ga_command_state_init(GAState *s, GACommandState *cs)
>>   {
>> --
>> 1.7.12.4
>
>
> .
>
diff mbox

Patch

diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 1010e86..02c6b44 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -2087,6 +2087,37 @@  int64_t qmp_guest_set_memory_blocks(GuestMemoryBlockList *mem_blks,
     return processed;
 }
 
+int64_t qmp_guest_get_memory_block_size(Error **errp)
+{
+    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__) */
 
 void qmp_guest_suspend_disk(Error **errp)
@@ -2135,6 +2166,12 @@  int64_t qmp_guest_set_memory_blocks(GuestMemoryBlockList *mem_blks,
     return -1;
 }
 
+int64_t qmp_guest_get_memory_block_size(Error **errp)
+{
+    error_set(errp, QERR_UNSUPPORTED);
+    return -1;
+}
+
 #endif
 
 #if !defined(CONFIG_FSFREEZE)
@@ -2221,12 +2258,6 @@  GList *ga_command_blacklist_init(GList *blacklist)
     return blacklist;
 }
 
-int64_t qmp_guest_get_memory_block_size(Error **errp)
-{
-    error_set(errp, QERR_UNSUPPORTED);
-    return -1;
-}
-
 /* register init/cleanup routines for stateful command groups */
 void ga_command_state_init(GAState *s, GACommandState *cs)
 {