qga: add three logical memory hotplug related commands
cover qga: add three logical memory hotplug related commands
Hi,
This patch series add three guest commands about memory block:
guest-get-memory-blocks, guest-set-memory-blocks, guest-get-memory-block-size.
With these three commands, we can get information about guest's memory block online/offline status and memory block size (unit of memory online/offline operation ). Also, we can change guest's memory block status (Logical memory hotplug/unplug) from host.
zhanghailiang (6):
qga: introduce three guest memory block commands with stubs
qga: introduce three help functions for memory block functions
qga: implement qmp_guest_get_memory_blocks() for Linux with sysfs
qga: implement qmp_guest_set_memory_blocks() for Linux with sysfs
qga: implement qmp_guest_get_memory_block_size() for Linux with sysfs
qga: add memory block command that unsupported to blacklist
qga/commands-posix.c | 266 ++++++++++++++++++++++++++++++++++++++++++++++++++- qga/commands-win32.c | 21 ++++ qga/qapi-schema.json | 88 +++++++++++++++++ 3 files changed, 374 insertions(+), 1 deletion(-)
Signature · 1 line
1.7.12.4
RFC PATCH 1/6 qga: introduce three guest memory block commands with stubs
Introduce three new guest commands:
guest-get-memory-blocks, guest-set-memory-blocks, guest-get-memory-block-size.
With these three commands, we can support online/offline guest's memory block (logical memory hotplug/unplug) as required from host.
--- qga/commands-posix.c | 19 ++++++++++++ qga/commands-win32.c | 19 ++++++++++++ qga/qapi-schema.json | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+)
qga/commands-posix.c +19 -0
@@ -1996,6 +1996,25 @@ GList *ga_command_blacklist_init(GList *blacklist)return blacklist; } +GuestMemoryBlockList *qmp_guest_get_memory_blocks (Error **errp) +{ +error_set (errp,QERR_UNSUPPORTED ); +return NULL ; +} + +int64_t qmp_guest_set_memory_blocks (GuestMemoryBlockList *mem_blks, +Error **errp) +{ +error_set (errp,QERR_UNSUPPORTED ); +return -1 ; +} + +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) {
qga/commands-win32.c +19 -0
@@ -446,6 +446,25 @@ int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp)return -1 ; } +GuestMemoryBlockList *qmp_guest_get_memory_blocks (Error **errp) +{ +error_set (errp,QERR_UNSUPPORTED ); +return NULL ; +} + +int64_t qmp_guest_set_memory_blocks (GuestMemoryBlockList *mem_blks, +Error **errp) +{ +error_set (errp,QERR_UNSUPPORTED ); +return -1 ; +} + +int64_t qmp_guest_get_memory_block_size (Error **errp) +{ +error_set (errp,QERR_UNSUPPORTED ); +return -1 ; +} +/* add unsupported commands to the blacklist */ GList *ga_command_blacklist_init (GList *blacklist) {
qga/qapi-schema.json +88 -0
91 lines not on this page · raw message
Signature · 1 line
1.7.12.4
Re: [Qemu-devel] [PATCH RFC for-2.3 1/6] qga: introduce three guest memory block commands with stubs
Quoting zhanghailiang (2014-12-06 00:59:14)
Quoted 78 lines
Introduce three new guest commands:
guest-get-memory-blocks, guest-set-memory-blocks, guest-get-memory-block-size.With these three commands, we can support online/offline guest's memory block (logical memory hotplug/unplug) as required from host.
Signed-off-by zhanghailiang <[email protected]>--- qga/commands-posix.c | 19 ++++++++++++ qga/commands-win32.c | 19 ++++++++++++ qga/qapi-schema.json | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+)qga/commands-posix.c +19
-0@@ -1996,6 +1996,25 @@ GList *ga_command_blacklist_init(GList *blacklist)return blacklist; } +GuestMemoryBlockList *qmp_guest_get_memory_blocks (Error **errp) +{ +error_set (errp,QERR_UNSUPPORTED ); +return NULL ; +} + +int64_t qmp_guest_set_memory_blocks (GuestMemoryBlockList *mem_blks, +Error **errp) +{ +error_set (errp,QERR_UNSUPPORTED ); +return -1 ; +} + +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) {qga/commands-win32.c +19
-0@@ -446,6 +446,25 @@ int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp)return -1 ; } +GuestMemoryBlockList *qmp_guest_get_memory_blocks (Error **errp) +{ +error_set (errp,QERR_UNSUPPORTED ); +return NULL ; +} + +int64_t qmp_guest_set_memory_blocks (GuestMemoryBlockList *mem_blks, +Error **errp) +{ +error_set (errp,QERR_UNSUPPORTED ); +return -1 ; +} + +int64_t qmp_guest_get_memory_block_size (Error **errp) +{ +error_set (errp,QERR_UNSUPPORTED ); +return -1 ; +} +/* add unsupported commands to the blacklist */ GList *ga_command_blacklist_init (GList *blacklist) {qga/qapi-schema.json +0
-0
qga/qapi-schema.json line 747
Quoted 10 lines
qga/qapi-schema.json +7
-0@@ -738,3 +738,91 @@ ## { 'command': 'guest-get-fsinfo', 'returns': ['GuestFilesystemInfo'] } + +## +# @GuestMemoryBlock: +# +# @phys_index: Arbitrary guest-specific unique identifier of the MEMORY BLOCK. +# +# @online: Whether the MEMORY BLOCK is enabled in logically.
Not sure what was intended with "in logically". Logically enabled? Enabled in guest maybe?
qga/qapi-schema.json line 749
Quoted 2 lines
qga/qapi-schema.json +2
-0+# +# @can-offline: #optional Whether offlining the MEMORY BLOCK is possible. This member
This line and a few below go beyond 80-char limit
qga/qapi-schema.json line 759
Quoted 10 lines
qga/qapi-schema.json +10
-0+# is always filled in by the guest agent when the structure is +# returned, and always ignored on input (hence it can be omitted +# then). +# +# Since: 2.3 +## +{ 'type': 'GuestMemoryBlock', + 'data': {'phys_index': 'uint64', + 'online': 'bool', + '*can-offline': 'bool'} }
'phys-index' would be the convention
Quoted 40 lines
qga/qapi-schema.json +39
-0+ +## +# @guest-get-memory-blocks: +# +# Retrieve the list of the guest's memory blocks. +# +# This is a read-only operation. +# +# Returns: The list of all memory blocks the guest knows about. +# Each memory block is put on the list exactly once, but their order +# is unspecified. +# +# Since: 2.3 +## +{ 'command': 'guest-get-memory-blocks', + 'returns': ['GuestMemoryBlock'] } + +## +# @guest-set-memory-blocks: +# +# Attempt to reconfigure (currently: enable/disable) state of memory blocks +# inside the guest. +# +# The input list is processed node by node in order. In each node @phys_index +# is used to look up the guest MEMORY BLOCK, for which @online specifies the requested +# state. The set of distinct @phys_index's is only required to be a subset of +# the guest-supported identifiers. There's no restriction on list length or on +# repeating the same @phys_index (with possibly different @online field). +# Preferably the input list should describe a modified subset of +# @guest-get-memory-blocks' return value. +# +# Returns: The length of the initial sublist that has been successfully +# processed. The guest agent maximizes this value. Possible cases: +# +# 0: if the @mem-blks list was empty on input. Guest state +# has not been changed. Otherwise, +# +# Error: processing the first node of @mem-blks failed for the +# reason returned. Guest state has not been changed.
qga/qapi-schema.json line 808
Quoted 10 lines
qga/qapi-schema.json +10
-0+# Otherwise, +# +# < length(@mem-blks): more than zero initial nodes have been processed, +# but not the entire @mem-blks list. Guest state has +# changed accordingly. To retrieve the error +# (assuming it persists), repeat the call with the +# successfully processed initial sublist removed. +# Otherwise, +# +# length(@mem-blks): call successful.
I know this is how we handle set-vcpus, but repeating set-memory calls to get individual errors seems kind of painful in retrospect, and in this case, where there multiple points in the call which may fail, I'm not sure how useful an errno response would be. Perhaps we should return something like this instead:
{ 'enum': 'GuestMemoryBlockResponseType',
'data': ['success', 'not-found', 'operation-not-supported', 'operation-failed', ...]}
{ 'type': 'GuestMemoryBlockResponse',
'data': { 'response': 'GuestMemoryResponseType',
'*error-code': 'int' }}
{ 'command': 'guest-set-memory-blocks',
'data': { 'mem-blks': ['GuestMemoryBlock'] },
'returns': ['GuestMemoryBlockResponse'] }
Where there's 1 response entry for each entry in mem-blk parameter. Alternatively, we could include the phys_index in the response entries, but since multiple requests for a particular block are accepted I think that would be more difficult to make sense of.
Quoted 22 lines
qga/qapi-schema.json +20
-0+# +# Since: 2.3 +## +{ 'command': 'guest-set-memory-blocks', + 'data': {'mem-blks': ['GuestMemoryBlock'] }, + 'returns': 'int' } + +## +# @guest-get-memory-block-size: +# +# Get the the size (in bytes) of a memory block in guest. +# It is the unit of Memory online/offline operation (also called Logical Memory Hotplug). +# +# Returns: memory block size in bytes. +# +# Since 2.3 +## +{ 'command': 'guest-get-memory-block-size', + 'returns': 'int' } +Signature · 1 line
1.7.12.4
Re: [Qemu-devel] [PATCH RFC for-2.3 1/6] qga: introduce three guest memory block commands with stubs
Quoted 84 lines · Michael Roth
Quoting zhanghailiang (2014-12-06 00:59:14)
Quoted 83 lines
Introduce three new guest commands:
guest-get-memory-blocks, guest-set-memory-blocks, guest-get-memory-block-size.With these three commands, we can support online/offline guest's memory block (logical memory hotplug/unplug) as required from host.
Signed-off-by zhanghailiang <[email protected]>--- qga/commands-posix.c | 19 ++++++++++++ qga/commands-win32.c | 19 ++++++++++++ qga/qapi-schema.json | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+)qga/commands-posix.c +19
-0@@ -1996,6 +1996,25 @@ GList *ga_command_blacklist_init(GList *blacklist)return blacklist; } +GuestMemoryBlockList *qmp_guest_get_memory_blocks (Error **errp) +{ +error_set (errp,QERR_UNSUPPORTED ); +return NULL ; +} + +int64_t qmp_guest_set_memory_blocks (GuestMemoryBlockList *mem_blks, +Error **errp) +{ +error_set (errp,QERR_UNSUPPORTED ); +return -1 ; +} + +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) {qga/commands-win32.c +19
-0@@ -446,6 +446,25 @@ int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp)return -1 ; } +GuestMemoryBlockList *qmp_guest_get_memory_blocks (Error **errp) +{ +error_set (errp,QERR_UNSUPPORTED ); +return NULL ; +} + +int64_t qmp_guest_set_memory_blocks (GuestMemoryBlockList *mem_blks, +Error **errp) +{ +error_set (errp,QERR_UNSUPPORTED ); +return -1 ; +} + +int64_t qmp_guest_get_memory_block_size (Error **errp) +{ +error_set (errp,QERR_UNSUPPORTED ); +return -1 ; +} +/* add unsupported commands to the blacklist */ GList *ga_command_blacklist_init (GList *blacklist) {qga/qapi-schema.json +2
-0@@ -738,3 +738,91 @@ ## { 'command': 'guest-get-fsinfo', 'returns': ['GuestFilesystemInfo'] } + +##
Quoted 9 lines
qga/qapi-schema.json line 747
Quoted 5 lines
qga/qapi-schema.json +5
-0+# @GuestMemoryBlock: +# +# @phys_index: Arbitrary guest-specific unique identifier of the MEMORY BLOCK. +# +# @online: Whether the MEMORY BLOCK is enabled in logically.Not sure what was intended with "in logically". Logically enabled? Enabled in guest maybe?
It should be in 'guest', will fix it in next version. Thanks.
Quoted 5 lines
qga/qapi-schema.json line 749
Quoted 2 lines
qga/qapi-schema.json +2
-0+# +# @can-offline: #optional Whether offlining the MEMORY BLOCK is possible. This memberThis line and a few below go beyond 80-char limit
Will fix that.
Quoted 4 lines
Quoted 4 lines
qga/qapi-schema.json +4
-0+# is always filled in by the guest agent when the structure is +# returned, and always ignored on input (hence it can be omitted +# then). +#
Quoted 9 lines
qga/qapi-schema.json line 759
Quoted 6 lines
qga/qapi-schema.json +6
-0+# Since: 2.3 +## +{ 'type': 'GuestMemoryBlock', + 'data': {'phys_index': 'uint64', + 'online': 'bool', + '*can-offline': 'bool'} }'phys-index' would be the convention
OK, that is a typo, fix it in next version.
Quoted 17 lines
Quoted 17 lines
qga/qapi-schema.json +17
-0+ +## +# @guest-get-memory-blocks: +# +# Retrieve the list of the guest's memory blocks. +# +# This is a read-only operation. +# +# Returns: The list of all memory blocks the guest knows about. +# Each memory block is put on the list exactly once, but their order +# is unspecified. +# +# Since: 2.3 +## +{ 'command': 'guest-get-memory-blocks', + 'returns': ['GuestMemoryBlock'] } +
Quoted 9 lines
qga/qapi-schema.json line 784
Quoted 8 lines
qga/qapi-schema.json +8
-0+## +# @guest-set-memory-blocks: +# +# Attempt to reconfigure (currently: enable/disable) state of memory blocks +# inside the guest. +# +# The input list is processed node by node in order. In each node @phys_index +# is used to look up the guest MEMORY BLOCK, for which @online specifies the requested
OK.
Quoted 19 lines
Quoted 19 lines
qga/qapi-schema.json +19
-0+# state. The set of distinct @phys_index's is only required to be a subset of +# the guest-supported identifiers. There's no restriction on list length or on +# repeating the same @phys_index (with possibly different @online field). +# Preferably the input list should describe a modified subset of +# @guest-get-memory-blocks' return value. +# +# Returns: The length of the initial sublist that has been successfully +# processed. The guest agent maximizes this value. Possible cases: +# +# 0: if the @mem-blks list was empty on input. Guest state +# has not been changed. Otherwise, +# +# Error: processing the first node of @mem-blks failed for the +# reason returned. Guest state has not been changed. +# Otherwise, +# +# < length(@mem-blks): more than zero initial nodes have been processed, +# but not the entire @mem-blks list. Guest state has +# changed accordingly. To retrieve the error
Quoted 8 lines
qga/qapi-schema.json line 808
Quoted 5 lines
qga/qapi-schema.json +5
-0+# (assuming it persists), repeat the call with the +# successfully processed initial sublist removed. +# Otherwise, +# +# length(@mem-blks): call successful.I know this is how we handle set-vcpus, but repeating set-memory calls to get individual errors seems kind of painful in retrospect, and in this case, where
Yes, compared with set-vcpus, we may repeat more times for set-memory.
Quoted 3 lines
there multiple points in the call which may fail, I'm not sure how useful an errno response would be. Perhaps we should return something like this instead:
Hmm, maybe this is really useful, for memory logical hotplug, it is a little complex. For some old kernel, it does not supporting this operation (online/offline by sysfs) at all. Sometimes we may not find the corresponding memoryXXX directory because we do physical memory hot-remove at the same time or a physical memory hot-add is still in fly.
We can choose different action (retry/report error, etc) according to the result.
Quoted 3 lines
{ 'enum': 'GuestMemoryBlockResponseType',
'data': ['success', 'not-found', 'operation-not-supported', 'operation-failed', ...]}
We should give definite meaning to the different error types.
Quoted 4 lines
{ 'type': 'GuestMemoryBlockResponse',
'data': { 'response': 'GuestMemoryResponseType','*error-code': 'int' }}
Quoted 9 lines
{ 'command': 'guest-set-memory-blocks',
'data': { 'mem-blks': ['GuestMemoryBlock'] },
'returns': ['GuestMemoryBlockResponse'] }Where there's 1 response entry for each entry in mem-blk parameter. Alternatively, we could include the
phys_indexin the response entries, but since multiple requests for a particular block are accepted I think that would be more difficult to make sense of.
That is really a good idea, i will look into it, and try to implement it in next version. ;)
Thanks,
zhanghailiang
Quoted 26 lines
Quoted 21 lines
qga/qapi-schema.json +20
-1+# +# Since: 2.3 +## +{ 'command': 'guest-set-memory-blocks', + 'data': {'mem-blks': ['GuestMemoryBlock'] }, + 'returns': 'int' } + +## +# @guest-get-memory-block-size: +# +# Get the the size (in bytes) of a memory block in guest. +# It is the unit of Memory online/offline operation (also called Logical Memory Hotplug). +# +# Returns: memory block size in bytes. +# +# Since 2.3 +## +{ 'command': 'guest-get-memory-block-size', + 'returns': 'int' } + --Quoted 1 line
1.7.12.4
.
RFC PATCH 2/6 qga: introduce three help functions for memory block functions
In reply to zhanghailiang--- qga/commands-posix.c | 130 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+)
qga/commands-posix.c +130 -0
@@ -1875,6 +1875,136 @@ int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp)return processed; } +static void ga_read_sysfs_file (int dirfd,const char *pathname,char *buf, +int size,Error **errp) +{ +int fd; +int res; + + errno =0 ; + fd =openat (dirfd, pathname,O_RDONLY ); +if (fd ==-1 ) { +error_setg_errno (errp, errno,"open sysfs file \"%s\"" , pathname); +return ; + } + + res =pread (fd, buf, size,0 ); +if (res ==-1 ) { +error_setg_errno (errp, errno,"pread sysfs file \"%s\"" , pathname); + }else if (res ==0 ) { +error_setg (errp,"pread sysfs file \"%s\": unexpected EOF" , pathname); + } + res =close (fd); +g_assert (res ==0 ); +} + +static void ga_write_sysfs_file (int dirfd,const char *pathname, +const char *buf,int size,Error **errp) +{ +int fd; +int res; + + errno =0 ; + fd =openat (dirfd, pathname,O_WRONLY ); +if (fd ==-1 ) { +error_setg_errno (errp, errno,"open sysfs file \"%s\"" , pathname); +return ; + } + +if (pwrite (fd, buf, size,0 ) ==-1 ) { +error_setg_errno (errp, errno,"pwrite sysfs file \"%s\"" , pathname); + } + + res =close (fd); +g_assert (res ==0 ); +} + +/* Transfer online/offline status between @mem_blk and the guest system. +* +* On input either @errp or *@errp must be NULL. +* +* In system-to-@mem_blk direction, the following @mem_blk fields are accessed: +* - R: mem_blk->phys_index +* - W: mem_blk->online +* - W: mem_blk->can_offline +* +* In @mem_blk-to-system direction, the following @mem_blk fields are accessed: +* - R: mem_blk->phys_index +* - R: mem_blk->online +*- R: mem_blk->can_offline +* Written members remain unmodified on error. +*/ +static void transfer_memory_block (GuestMemoryBlock *mem_blk,bool sys2memblk, +Error **errp) +{ +char *dirpath; +int dirfd; +int res; +char *status; +Error *local_err =NULL ; + + dirpath =g_strdup_printf ("/sys/devices/system/memory/memory%" PRId64"/" , + mem_blk->phys_index); + dirfd =open (dirpath,O_RDONLY |O_DIRECTORY ); +if (dirfd ==-1 ) { +error_setg_errno (errp, errno,"open(\"%s\")" , dirpath); +g_free (dirpath); +return ; + } +g_free (dirpath); + + status =g_malloc0 (10 ); +ga_read_sysfs_file (dirfd,"state" , status,10 , &local_err); +if (local_err) { +/* treat with sysfs file that not exist in old kernel */ +if (errno ==ENOENT ) { +error_free (local_err); +if (sys2memblk) { + mem_blk->online = true; + mem_blk->can_offline = false; + }else if (!mem_blk->online) { +error_setg (errp,"memory block #%" PRId64" can't be " +"offlined" , mem_blk->phys_index); + } + }else { +error_propagate (errp, local_err); + } +return ; + } + +if (sys2memblk) { +char removable ='0' ; + + mem_blk->online = (strncmp (status,"online" ,6 ) ==0 ); + +ga_read_sysfs_file (dirfd,"removable" , &removable,1 , &local_err); +if (local_err) { +/* if no 'removable' file, it does't support offline mem blk */ +if (errno ==ENOENT ) { +error_free (local_err); + mem_blk->can_offline = false; + }else { +error_propagate (errp, local_err); + } + }else { + mem_blk->can_offline = (removable !='0' ); + } + }else { +if (mem_blk->online != (strncmp (status,"online" ,6 ) ==0 )) { +char *new_state = mem_blk->online ?g_strdup ("online" ) : +g_strdup ("offline" ); + +ga_write_sysfs_file (dirfd,"state" , new_state,strlen (new_state), + errp); +g_free (new_state); + }/* otherwise pretend successful re-(on|off)-lining */ + } + +g_free (status); + res =close (dirfd); +g_assert (res ==0 ); +} +#else /* defined(__linux__) */ void qmp_guest_suspend_disk (Error **errp)
Signature · 1 line
1.7.12.4
Re: [Qemu-devel] [PATCH RFC for-2.3 2/6] qga: introduce three help functions for memory block functions
Quoting zhanghailiang (2014-12-06 00:59:15)
qga/commands-posix.c int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp) · line 1876
Quoted 12 lines
Signed-off-by zhanghailiang <[email protected]>--- qga/commands-posix.c | 130 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+)qga/commands-posix.c +0
-0@@ -1875,6 +1875,136 @@ int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp)return processed; }
I think these would break build bisectability. Please move these into the patches which introduce the first users.
Quoted 12 lines
qga/commands-posix.c +11
-0+static void ga_read_sysfs_file (int dirfd,const char *pathname,char *buf, +int size,Error **errp) +{ +int fd; +int res; + + errno =0 ; + fd =openat (dirfd, pathname,O_RDONLY ); +if (fd ==-1 ) { +error_setg_errno (errp, errno,"open sysfs file \"%s\"" , pathname); +return ;
qga/commands-posix.c int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp) · line 1898
Quoted 10 lines
qga/commands-posix.c +10
-0+ } + + res =pread (fd, buf, size,0 ); +if (res ==-1 ) { +error_setg_errno (errp, errno,"pread sysfs file \"%s\"" , pathname); + }else if (res ==0 ) { +error_setg (errp,"pread sysfs file \"%s\": unexpected EOF" , pathname); + } + res =close (fd); +g_assert (res ==0 );
This should also be propagated up as an error, killing the guest agent should be avoided when possible.
Quoted 64 lines
qga/commands-posix.c +64
-0+} + +static void ga_write_sysfs_file (int dirfd,const char *pathname, +const char *buf,int size,Error **errp) +{ +int fd; +int res; + + errno =0 ; + fd =openat (dirfd, pathname,O_WRONLY ); +if (fd ==-1 ) { +error_setg_errno (errp, errno,"open sysfs file \"%s\"" , pathname); +return ; + } + +if (pwrite (fd, buf, size,0 ) ==-1 ) { +error_setg_errno (errp, errno,"pwrite sysfs file \"%s\"" , pathname); + } + + res =close (fd); +g_assert (res ==0 ); +} + +/* Transfer online/offline status between @mem_blk and the guest system. +* +* On input either @errp or *@errp must be NULL. +* +* In system-to-@mem_blk direction, the following @mem_blk fields are accessed: +* - R: mem_blk->phys_index +* - W: mem_blk->online +* - W: mem_blk->can_offline +* +* In @mem_blk-to-system direction, the following @mem_blk fields are accessed: +* - R: mem_blk->phys_index +* - R: mem_blk->online +*- R: mem_blk->can_offline +* Written members remain unmodified on error. +*/ +static void transfer_memory_block (GuestMemoryBlock *mem_blk,bool sys2memblk, +Error **errp) +{ +char *dirpath; +int dirfd; +int res; +char *status; +Error *local_err =NULL ; + + dirpath =g_strdup_printf ("/sys/devices/system/memory/memory%" PRId64"/" , + mem_blk->phys_index); + dirfd =open (dirpath,O_RDONLY |O_DIRECTORY ); +if (dirfd ==-1 ) { +error_setg_errno (errp, errno,"open(\"%s\")" , dirpath); +g_free (dirpath); +return ; + } +g_free (dirpath); + + status =g_malloc0 (10 ); +ga_read_sysfs_file (dirfd,"state" , status,10 , &local_err); +if (local_err) { +/* treat with sysfs file that not exist in old kernel */ +if (errno ==ENOENT ) { +error_free (local_err); +if (sys2memblk) {
qga/commands-posix.c int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp) · line 1972
Quoted 10 lines
qga/commands-posix.c +10
-0+ mem_blk->online = true; + mem_blk->can_offline = false; + }else if (!mem_blk->online) { +error_setg (errp,"memory block #%" PRId64" can't be " +"offlined" , mem_blk->phys_index); + } + }else { +error_propagate (errp, local_err); + } +return ;
Need to free 'status' here, and close 'dirfd'. perhaps just a goto to the end of the function since you already have common cleanup there. And, if you use 'local_err' in place of 'err' for error_set, you can maybe move all your error_propagate calls there as well.
Quoted 40 lines
qga/commands-posix.c +35
-0+ } + +if (sys2memblk) { +char removable ='0' ; + + mem_blk->online = (strncmp (status,"online" ,6 ) ==0 ); + +ga_read_sysfs_file (dirfd,"removable" , &removable,1 , &local_err); +if (local_err) { +/* if no 'removable' file, it does't support offline mem blk */ +if (errno ==ENOENT ) { +error_free (local_err); + mem_blk->can_offline = false; + }else { +error_propagate (errp, local_err); + } + }else { + mem_blk->can_offline = (removable !='0' ); + } + }else { +if (mem_blk->online != (strncmp (status,"online" ,6 ) ==0 )) { +char *new_state = mem_blk->online ?g_strdup ("online" ) : +g_strdup ("offline" ); + +ga_write_sysfs_file (dirfd,"state" , new_state,strlen (new_state), + errp); +g_free (new_state); + }/* otherwise pretend successful re-(on|off)-lining */ + } + +g_free (status); + res =close (dirfd); + g_assert(res == 0); +} +#else /* defined(__linux__) */ void qmp_guest_suspend_disk (Error **errp)Signature · 1 line
1.7.12.4
Re: [Qemu-devel] [PATCH RFC for-2.3 2/6] qga: introduce three help functions for memory block functions
Quoted 6 lines · Michael Roth
Quoting zhanghailiang (2014-12-06 00:59:15)
Quoted 5 lines
Signed-off-by zhanghailiang <[email protected]>--- qga/commands-posix.c | 130 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+)
Quoted 11 lines
qga/commands-posix.c int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp) · line 1876
Quoted 7 lines
qga/commands-posix.c +0
-0@@ -1875,6 +1875,136 @@ int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp)return processed; }I think these would break build bisectability. Please move these into the patches which introduce the first users.
OK, will squash patch into patch 3.
Quoted 17 lines
Quoted 17 lines
qga/commands-posix.c +16
-0+static void ga_read_sysfs_file (int dirfd,const char *pathname,char *buf, +int size,Error **errp) +{ +int fd; +int res; + + errno =0 ; + fd =openat (dirfd, pathname,O_RDONLY ); +if (fd ==-1 ) { +error_setg_errno (errp, errno,"open sysfs file \"%s\"" , pathname); +return ; + } + + res =pread (fd, buf, size,0 ); +if (res ==-1 ) { +error_setg_errno (errp, errno,"pread sysfs file \"%s\"" , pathname);
Quoted 9 lines
qga/commands-posix.c int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp) · line 1898
Quoted 5 lines
qga/commands-posix.c +5
-0+ }else if (res ==0 ) { +error_setg (errp,"pread sysfs file \"%s\": unexpected EOF" , pathname); + } + res =close (fd); +g_assert (res ==0 );This should also be propagated up as an error, killing the guest agent should be avoided when possible.
Yes, you are right. I noted that, in most cases, we ignore the return value of close() in qemu codes, so i will choose to ignore here too, is it OK?
Quoted 71 lines
Quoted 71 lines
qga/commands-posix.c +71
-0+} + +static void ga_write_sysfs_file (int dirfd,const char *pathname, +const char *buf,int size,Error **errp) +{ +int fd; +int res; + + errno =0 ; + fd =openat (dirfd, pathname,O_WRONLY ); +if (fd ==-1 ) { +error_setg_errno (errp, errno,"open sysfs file \"%s\"" , pathname); +return ; + } + +if (pwrite (fd, buf, size,0 ) ==-1 ) { +error_setg_errno (errp, errno,"pwrite sysfs file \"%s\"" , pathname); + } + + res =close (fd); +g_assert (res ==0 ); +} + +/* Transfer online/offline status between @mem_blk and the guest system. +* +* On input either @errp or *@errp must be NULL. +* +* In system-to-@mem_blk direction, the following @mem_blk fields are accessed: +* - R: mem_blk->phys_index +* - W: mem_blk->online +* - W: mem_blk->can_offline +* +* In @mem_blk-to-system direction, the following @mem_blk fields are accessed: +* - R: mem_blk->phys_index +* - R: mem_blk->online +*- R: mem_blk->can_offline +* Written members remain unmodified on error. +*/ +static void transfer_memory_block (GuestMemoryBlock *mem_blk,bool sys2memblk, +Error **errp) +{ +char *dirpath; +int dirfd; +int res; +char *status; +Error *local_err =NULL ; + + dirpath =g_strdup_printf ("/sys/devices/system/memory/memory%" PRId64"/" , + mem_blk->phys_index); + dirfd =open (dirpath,O_RDONLY |O_DIRECTORY ); +if (dirfd ==-1 ) { +error_setg_errno (errp, errno,"open(\"%s\")" , dirpath); +g_free (dirpath); +return ; + } +g_free (dirpath); + + status =g_malloc0 (10 ); +ga_read_sysfs_file (dirfd,"state" , status,10 , &local_err); +if (local_err) { +/* treat with sysfs file that not exist in old kernel */ +if (errno ==ENOENT ) { +error_free (local_err); +if (sys2memblk) { + mem_blk->online = true; + mem_blk->can_offline = false; + }else if (!mem_blk->online) { +error_setg (errp,"memory block #%" PRId64" can't be " +"offlined" , mem_blk->phys_index); + } + }else {
Quoted 9 lines
qga/commands-posix.c int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp) · line 1972
Quoted 3 lines
qga/commands-posix.c +3
-0+error_propagate (errp, local_err); + } +return ;Need to free 'status' here, and close 'dirfd'. perhaps just a goto to the end of the function since you already have common cleanup there. And, if you use '
local_err' in place of 'err' forerror_set, you can maybe move all yourerror_propagatecalls there as well.
Good catch, will fix it in next version, thanks.
Quoted 44 lines
Quoted 39 lines
qga/commands-posix.c +35
-1+ } + +if (sys2memblk) { +char removable ='0' ; + + mem_blk->online = (strncmp (status,"online" ,6 ) ==0 ); + +ga_read_sysfs_file (dirfd,"removable" , &removable,1 , &local_err); +if (local_err) { +/* if no 'removable' file, it does't support offline mem blk */ +if (errno ==ENOENT ) { +error_free (local_err); + mem_blk->can_offline = false; + }else { +error_propagate (errp, local_err); + } + }else { + mem_blk->can_offline = (removable !='0' ); + } + }else { +if (mem_blk->online != (strncmp (status,"online" ,6 ) ==0 )) { +char *new_state = mem_blk->online ?g_strdup ("online" ) : +g_strdup ("offline" ); + +ga_write_sysfs_file (dirfd,"state" , new_state,strlen (new_state), + errp); +g_free (new_state); + }/* otherwise pretend successful re-(on|off)-lining */ + } + +g_free (status); + res =close (dirfd); + g_assert(res == 0); +} +#else /* defined(__linux__) */ void qmp_guest_suspend_disk (Error **errp) --Quoted 1 line
1.7.12.4
.
RFC PATCH 3/6 qga: implement qmp_guest_get_memory_blocks() for Linux with sysfs
In reply to zhanghailiangWe can get guest's memory block information by using command "guest-get-memory-blocks", the returned value contains a list of memory block info, such as phys_index, online state, can-offline info.
--- qga/commands-posix.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 6 deletions(-)
qga/commands-posix.c +60 -6
@@ -2005,6 +2005,60 @@ static void transfer_memory_block(GuestMemoryBlock *mem_blk, bool sys2memblk,g_assert (res ==0 ); } +GuestMemoryBlockList *qmp_guest_get_memory_blocks (Error **errp) +{ +GuestMemoryBlockList *head, **link; +Error *local_err =NULL ; +struct dirent *de; +DIR *dp; + + head =NULL ; + link = &head; + + dp =opendir ("/sys/devices/system/memory/" ); +if (!dp) { +error_setg_errno (errp, errno,"Can't open directory" +"\"/sys/devices/system/memory/\"\n" ); +return NULL ; + } + +/* Note: the phys_index of memory block may be discontinuous, +* this is because a memblk is the unit of the Sparse Memory design, which +* allows discontinuous memory ranges (ex. NUMA), so here we should +* traverse the memory block directory. +*/ +while ((de =readdir (dp)) !=NULL ) { +GuestMemoryBlock *mem_blk; +GuestMemoryBlockList *entry; + +if ((strncmp (de->d_name,"memory" ,6 ) !=0 ) || + !(de->d_type &DT_DIR )) { +continue ; + } + + mem_blk =g_malloc0 (sizeof *mem_blk); +/* The d_name is "memoryXXX", phys_index is block id, same as XXX */ + mem_blk->phys_index =strtoul (&de->d_name[6 ],NULL ,10 ); + mem_blk->has_can_offline = true;/* lolspeak ftw */ +transfer_memory_block (mem_blk, true, &local_err); + + entry =g_malloc0 (sizeof *entry); + entry->value = mem_blk; + + *link = entry; + link = &entry->next; + } + +if (local_err ==NULL ) { +/* there's no guest with zero memroy blocks */ +g_assert (head !=NULL ); +return head; + } + +qapi_free_GuestMemoryBlockList (head); +error_propagate (errp, local_err); +return NULL ; +}#else /* defined(__linux__) */ void qmp_guest_suspend_disk (Error **errp)
@@ -2040,6 +2094,12 @@ int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp) return -1; } +GuestMemoryBlockList *qmp_guest_get_memory_blocks (Error **errp) +{ +error_set (errp,QERR_UNSUPPORTED ); +return NULL ; +} +#endif #if !defined(CONFIG_FSFREEZE )
@@ -2126,12 +2186,6 @@ GList *ga_command_blacklist_init(GList *blacklist)return blacklist; } -GuestMemoryBlockList *qmp_guest_get_memory_blocks (Error **errp) -{ -error_set (errp,QERR_UNSUPPORTED ); -return NULL ; -} -int64_t qmp_guest_set_memory_blocks (GuestMemoryBlockList *mem_blks,Error **errp) {
Signature · 1 line
1.7.12.4
Re: [Qemu-devel] [PATCH RFC for-2.3 3/6] qga: implement qmp_guest_get_memory_blocks() for Linux with sysfs
Quoting zhanghailiang (2014-12-06 00:59:16)
Quoted 42 lines
We can get guest's memory block information by using command "guest-get-memory-blocks", the returned value contains a list of memory block info, such as
phys_index, online state, can-offline info.Signed-off-by zhanghailiang <[email protected]>--- qga/commands-posix.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 6 deletions(-)qga/commands-posix.c +25
-0@@ -2005,6 +2005,60 @@ static void transfer_memory_block(GuestMemoryBlock *mem_blk, bool sys2memblk,g_assert (res ==0 ); } +GuestMemoryBlockList *qmp_guest_get_memory_blocks (Error **errp) +{ +GuestMemoryBlockList *head, **link; +Error *local_err =NULL ; +struct dirent *de; +DIR *dp; + + head =NULL ; + link = &head; + + dp =opendir ("/sys/devices/system/memory/" ); +if (!dp) { +error_setg_errno (errp, errno,"Can't open directory" +"\"/sys/devices/system/memory/\"\n" ); +return NULL ; + } + +/* Note: the phys_index of memory block may be discontinuous, +* this is because a memblk is the unit of the Sparse Memory design, which +* allows discontinuous memory ranges (ex. NUMA), so here we should +* traverse the memory block directory. +*/ +while ((de =readdir (dp)) !=NULL ) { +GuestMemoryBlock *mem_blk; +GuestMemoryBlockList *entry;
qga/commands-posix.c static void transfer_memory_block(GuestMemoryBlock *mem_blk, bool sys2memblk, · line 2042
Quoted 10 lines
qga/commands-posix.c +10
-0+ +if ((strncmp (de->d_name,"memory" ,6 ) !=0 ) || + !(de->d_type &DT_DIR )) { +continue ; + } + + mem_blk =g_malloc0 (sizeof *mem_blk); +/* The d_name is "memoryXXX", phys_index is block id, same as XXX */ + mem_blk->phys_index =strtoul (&de->d_name[6 ],NULL ,10 ); + mem_blk->has_can_offline = true;/* lolspeak ftw */
My initial thought as well :P
qga/commands-posix.c static void transfer_memory_block(GuestMemoryBlock *mem_blk, bool sys2memblk, · line 2053
Quoted 11 lines
qga/commands-posix.c +11
-0+transfer_memory_block (mem_blk, true, &local_err); + + entry =g_malloc0 (sizeof *entry); + entry->value = mem_blk; + + *link = entry; + link = &entry->next; + } + +if (local_err ==NULL ) { +/* there's no guest with zero memroy blocks */
typo
qga/commands-posix.c static void transfer_memory_block(GuestMemoryBlock *mem_blk, bool sys2memblk, · line 2054
Quoted 1 line
qga/commands-posix.c +1
-0+g_assert (head !=NULL );
As commented on in earlier patches, guest errors shouldnt crash the guest agent if it can be avoided.
Quoted 24 lines
qga/commands-posix.c +13
-0+ return head; + } + +qapi_free_GuestMemoryBlockList (head); +error_propagate (errp, local_err); +return NULL ; +}#else /* defined(__linux__) */ void qmp_guest_suspend_disk (Error **errp)@@ -2040,6 +2094,12 @@ int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp) return -1; } +GuestMemoryBlockList *qmp_guest_get_memory_blocks (Error **errp) +{ +error_set (errp,QERR_UNSUPPORTED ); +return NULL ; +} +#endif #if !defined(CONFIG_FSFREEZE )
qga/commands-posix.c GList *ga_command_blacklist_init(GList *blacklist) · line 2134
Quoted 9 lines
qga/commands-posix.c +0
-6@@ -2126,12 +2186,6 @@ GList *ga_command_blacklist_init(GList *blacklist)return blacklist; } -GuestMemoryBlockList *qmp_guest_get_memory_blocks (Error **errp) -{ -error_set (errp,QERR_UNSUPPORTED ); -return NULL ; -} -
Looks like some unecessary code movement made it's way into the patch. Please squash this change into original patch
Quoted 5 lines
qga/commands-posix.c +0
-0int64_t qmp_guest_set_memory_blocks (GuestMemoryBlockList *mem_blks,Error **errp) {Signature · 1 line
1.7.12.4
Re: [Qemu-devel] [PATCH RFC for-2.3 3/6] qga: implement qmp_guest_get_memory_blocks() for Linux with sysfs
Quoted 47 lines · Michael Roth
Quoting zhanghailiang (2014-12-06 00:59:16)
Quoted 46 lines
We can get guest's memory block information by using command "guest-get-memory-blocks", the returned value contains a list of memory block info, such as
phys_index, online state, can-offline info.Signed-off-by zhanghailiang <[email protected]>--- qga/commands-posix.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 6 deletions(-)qga/commands-posix.c +29
-0@@ -2005,6 +2005,60 @@ static void transfer_memory_block(GuestMemoryBlock *mem_blk, bool sys2memblk,g_assert (res ==0 ); } +GuestMemoryBlockList *qmp_guest_get_memory_blocks (Error **errp) +{ +GuestMemoryBlockList *head, **link; +Error *local_err =NULL ; +struct dirent *de; +DIR *dp; + + head =NULL ; + link = &head; + + dp =opendir ("/sys/devices/system/memory/" ); +if (!dp) { +error_setg_errno (errp, errno,"Can't open directory" +"\"/sys/devices/system/memory/\"\n" ); +return NULL ; + } + +/* Note: the phys_index of memory block may be discontinuous, +* this is because a memblk is the unit of the Sparse Memory design, which +* allows discontinuous memory ranges (ex. NUMA), so here we should +* traverse the memory block directory. +*/ +while ((de =readdir (dp)) !=NULL ) { +GuestMemoryBlock *mem_blk; +GuestMemoryBlockList *entry; + +if ((strncmp (de->d_name,"memory" ,6 ) !=0 ) || + !(de->d_type &DT_DIR )) { +continue ;
Quoted 9 lines
qga/commands-posix.c static void transfer_memory_block(GuestMemoryBlock *mem_blk, bool sys2memblk, · line 2042
Quoted 6 lines
qga/commands-posix.c +6
-0+ } + + mem_blk =g_malloc0 (sizeof *mem_blk); +/* The d_name is "memoryXXX", phys_index is block id, same as XXX */ + mem_blk->phys_index =strtoul (&de->d_name[6 ],NULL ,10 ); + mem_blk->has_can_offline = true;/* lolspeak ftw */ My initial thought as well :P
Ha, yes. ;)
Quoted 14 lines
qga/commands-posix.c static void transfer_memory_block(GuestMemoryBlock *mem_blk, bool sys2memblk, · line 2053
Quoted 11 lines
qga/commands-posix.c +11
-0+transfer_memory_block (mem_blk, true, &local_err); + + entry =g_malloc0 (sizeof *entry); + entry->value = mem_blk; + + *link = entry; + link = &entry->next; + } + +if (local_err ==NULL ) { +/* there's no guest with zero memroy blocks */ typo
Quoted 5 lines
qga/commands-posix.c static void transfer_memory_block(GuestMemoryBlock *mem_blk, bool sys2memblk, · line 2054
Quoted 1 line
qga/commands-posix.c +1
-0+g_assert (head !=NULL );As commented on in earlier patches, guest errors shouldnt crash the guest agent if it can be avoided.
OK.
Quoted 27 lines
Quoted 27 lines
qga/commands-posix.c +13
-0+ return head; + } + +qapi_free_GuestMemoryBlockList (head); +error_propagate (errp, local_err); +return NULL ; +}#else /* defined(__linux__) */ void qmp_guest_suspend_disk (Error **errp)@@ -2040,6 +2094,12 @@ int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp) return -1; } +GuestMemoryBlockList *qmp_guest_get_memory_blocks (Error **errp) +{ +error_set (errp,QERR_UNSUPPORTED ); +return NULL ; +} +#endif #if !defined(CONFIG_FSFREEZE )@@ -2126,12 +2186,6 @@ GList *ga_command_blacklist_init(GList *blacklist)return blacklist; }
Quoted 10 lines
qga/commands-posix.c GList *ga_command_blacklist_init(GList *blacklist) · line 2134
Quoted 6 lines
qga/commands-posix.c +0
-6-GuestMemoryBlockList *qmp_guest_get_memory_blocks (Error **errp) -{ -error_set (errp,QERR_UNSUPPORTED ); -return NULL ; -} -Looks like some unecessary code movement made it's way into the patch. Please squash this change into original patch
OK, will fix that. Thanks.
Quoted 9 lines
Quoted 5 lines
qga/commands-posix.c +0
-1int64_t qmp_guest_set_memory_blocks (GuestMemoryBlockList *mem_blks,Error **errp) { --1.7.12.4
.
RFC PATCH 4/6 qga: implement qmp_guest_set_memory_blocks() for Linux with sysfs
In reply to zhanghailiang--- qga/commands-posix.c | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-)
qga/commands-posix.c +35 -7
@@ -2059,6 +2059,34 @@ GuestMemoryBlockList *qmp_guest_get_memory_blocks(Error **errp)error_propagate (errp, local_err); return NULL; } + +int64_t qmp_guest_set_memory_blocks (GuestMemoryBlockList *mem_blks, +Error **errp) +{ +int64_t processed; +Error *local_err =NULL ; + + processed =0 ; +while (mem_blks !=NULL ) { +transfer_memory_block (mem_blks->value, false, &local_err); +if (local_err) { +break ; + } + ++processed; + mem_blks = mem_blks->next; + } + +if (local_err) { +if (processed ==0 ) { +error_propagate (errp, local_err); + }else { +error_free (local_err); + } + } + +return processed; +} +#else /* defined(__linux__) */ void qmp_guest_suspend_disk (Error **errp)
@@ -2100,6 +2128,13 @@ GuestMemoryBlockList *qmp_guest_get_memory_blocks(Error **errp) return NULL; } +int64_t qmp_guest_set_memory_blocks (GuestMemoryBlockList *mem_blks, +Error **errp) +{ +error_set (errp,QERR_UNSUPPORTED ); +return -1 ; +} +#endif #if !defined(CONFIG_FSFREEZE )
@@ -2186,13 +2221,6 @@ GList *ga_command_blacklist_init(GList *blacklist)return blacklist; } -int64_t qmp_guest_set_memory_blocks (GuestMemoryBlockList *mem_blks, -Error **errp) -{ -error_set (errp,QERR_UNSUPPORTED ); -return -1 ; -} -int64_t qmp_guest_get_memory_block_size (Error **errp) {error_set (errp,QERR_UNSUPPORTED );
Signature · 1 line
1.7.12.4
Re: [Qemu-devel] [PATCH RFC for-2.3 4/6] qga: implement qmp_guest_set_memory_blocks() for Linux with sysfs
Quoting zhanghailiang (2014-12-06 00:59:17)
Quoted 16 lines
Signed-off-by zhanghailiang <[email protected]>--- qga/commands-posix.c | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-)qga/commands-posix.c +3
-0@@ -2059,6 +2059,34 @@ GuestMemoryBlockList *qmp_guest_get_memory_blocks(Error **errp)error_propagate (errp, local_err);return NULL ; } + +int64_t qmp_guest_set_memory_blocks (GuestMemoryBlockList *mem_blks, +Error **errp)
qga/commands-posix.c GuestMemoryBlockList *qmp_guest_get_memory_blocks(Error **errp) · line 2074
Quoted 10 lines
qga/commands-posix.c +10
-0+{ +int64_t processed; +Error *local_err =NULL ; + + processed =0 ; +while (mem_blks !=NULL ) { +transfer_memory_block (mem_blks->value, false, &local_err); +if (local_err) { +break ; + }
The documentation claims to maximize the number of blocks we set in the event of an error, which would suggest we continue processing the remainder of the list rather than breaking here.
qga/commands-posix.c GuestMemoryBlockList *qmp_guest_get_memory_blocks(Error **errp) · line 2084
Quoted 10 lines
qga/commands-posix.c +10
-0+ ++processed; + mem_blks = mem_blks->next; + } + +if (local_err) { +if (processed ==0 ) { +error_propagate (errp, local_err); + }else { +error_free (local_err); + }
Really think a list of error/status would make it easier for management to make sense of things.
Quoted 23 lines
qga/commands-posix.c +12
-0+ } + +return processed; +} +#else /* defined(__linux__) */ void qmp_guest_suspend_disk (Error **errp)@@ -2100,6 +2128,13 @@ GuestMemoryBlockList *qmp_guest_get_memory_blocks(Error **errp) return NULL; } +int64_t qmp_guest_set_memory_blocks (GuestMemoryBlockList *mem_blks, +Error **errp) +{ +error_set (errp,QERR_UNSUPPORTED ); +return -1 ; +} +#endif #if !defined(CONFIG_FSFREEZE )
qga/commands-posix.c GList *ga_command_blacklist_init(GList *blacklist) · line 2195
Quoted 10 lines
qga/commands-posix.c +0
-7@@ -2186,13 +2221,6 @@ GList *ga_command_blacklist_init(GList *blacklist)return blacklist; } -int64_t qmp_guest_set_memory_blocks (GuestMemoryBlockList *mem_blks, -Error **errp) -{ -error_set (errp,QERR_UNSUPPORTED ); -return -1 ; -} -
Same comment here as with prior patch
Quoted 5 lines
qga/commands-posix.c +0
-0int64_t qmp_guest_get_memory_block_size (Error **errp) {error_set (errp,QERR_UNSUPPORTED );Signature · 1 line
1.7.12.4
Re: [Qemu-devel] [PATCH RFC for-2.3 4/6] qga: implement qmp_guest_set_memory_blocks() for Linux with sysfs
Quoted 23 lines · Michael Roth
Quoting zhanghailiang (2014-12-06 00:59:17)
Quoted 22 lines
Signed-off-by zhanghailiang <[email protected]>--- qga/commands-posix.c | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-)qga/commands-posix.c +9
-0@@ -2059,6 +2059,34 @@ GuestMemoryBlockList *qmp_guest_get_memory_blocks(Error **errp)error_propagate (errp, local_err);return NULL ; } + +int64_t qmp_guest_set_memory_blocks (GuestMemoryBlockList *mem_blks, +Error **errp) +{ +int64_t processed; +Error *local_err =NULL ; + + processed =0 ; +while (mem_blks !=NULL ) {
Quoted 9 lines
qga/commands-posix.c GuestMemoryBlockList *qmp_guest_get_memory_blocks(Error **errp) · line 2074
Quoted 4 lines
qga/commands-posix.c +4
-0+transfer_memory_block (mem_blks->value, false, &local_err); +if (local_err) { +break ; + }The documentation claims to maximize the number of blocks we set in the event of an error, which would suggest we continue processing the remainder of the list rather than breaking here.
OK, one more thing, should we fix like that for set-vcpus ?
Quoted 11 lines
qga/commands-posix.c GuestMemoryBlockList *qmp_guest_get_memory_blocks(Error **errp) · line 2084
Quoted 10 lines
qga/commands-posix.c +10
-0+ ++processed; + mem_blks = mem_blks->next; + } + +if (local_err) { +if (processed ==0 ) { +error_propagate (errp, local_err); + }else { +error_free (local_err); + }
Quoted 3 lines
Really think a list of error/status would make it easier for management to make sense of things.
Agreed :)
Quoted 26 lines
Quoted 26 lines
qga/commands-posix.c +12
-0+ } + +return processed; +} +#else /* defined(__linux__) */ void qmp_guest_suspend_disk (Error **errp)@@ -2100,6 +2128,13 @@ GuestMemoryBlockList *qmp_guest_get_memory_blocks(Error **errp) return NULL; } +int64_t qmp_guest_set_memory_blocks (GuestMemoryBlockList *mem_blks, +Error **errp) +{ +error_set (errp,QERR_UNSUPPORTED ); +return -1 ; +} +#endif #if !defined(CONFIG_FSFREEZE )@@ -2186,13 +2221,6 @@ GList *ga_command_blacklist_init(GList *blacklist)return blacklist; }
Quoted 10 lines
qga/commands-posix.c GList *ga_command_blacklist_init(GList *blacklist) · line 2195
Quoted 7 lines
qga/commands-posix.c +0
-7-int64_t qmp_guest_set_memory_blocks (GuestMemoryBlockList *mem_blks, -Error **errp) -{ -error_set (errp,QERR_UNSUPPORTED ); -return -1 ; -} -Same comment here as with prior patch
OK, thanks.
Quoted 9 lines
Quoted 5 lines
qga/commands-posix.c +0
-1int64_t qmp_guest_get_memory_block_size (Error **errp) {error_set (errp,QERR_UNSUPPORTED ); --1.7.12.4
.
RFC PATCH 5/6 qga: implement qmp_guest_get_memory_block_size() for Linux with sysfs
In reply to zhanghailiangThe 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.
--- qga/commands-posix.c | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-)
qga/commands-posix.c +37 -6
@@ -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) {
Signature · 1 line
1.7.12.4
Re: [Qemu-devel] [PATCH RFC for-2.3 5/6] qga: implement qmp_guest_get_memory_block_size() for Linux with sysfs
Quoting zhanghailiang (2014-12-06 00:59:18)
Quoted 2 lines
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.
Quoted 66 lines
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 <[email protected]>--- qga/commands-posix.c | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-)qga/commands-posix.c +37
-0@@ -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 )
qga/commands-posix.c GList *ga_command_blacklist_init(GList *blacklist) · line 2229
Quoted 9 lines
qga/commands-posix.c +0
-6@@ -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
Quoted 5 lines
qga/commands-posix.c +0
-0/* register init/cleanup routines for stateful command groups */ void ga_command_state_init (GAState *s,GACommandState *cs) {Signature · 1 line
1.7.12.4
Re: [Qemu-devel] [PATCH RFC for-2.3 5/6] qga: implement qmp_guest_get_memory_block_size() for Linux with sysfs
Quoted 10 lines · Michael Roth
Quoting zhanghailiang (2014-12-06 00:59:18)
Quoted 2 lines
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.
Quoted 69 lines
Quoted 69 lines
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 <[email protected]>--- qga/commands-posix.c | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-)qga/commands-posix.c +37
-0@@ -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; }
Quoted 9 lines
qga/commands-posix.c GList *ga_command_blacklist_init(GList *blacklist) · line 2229
Quoted 6 lines
qga/commands-posix.c +0
-6-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.
Quoted 9 lines
Quoted 5 lines
qga/commands-posix.c +0
-1/* register init/cleanup routines for stateful command groups */ void ga_command_state_init (GAState *s,GACommandState *cs) { --1.7.12.4
.
RFC PATCH 6/6 qga: add memory block command that unsupported to blacklist
In reply to zhanghailiangFor memory block command, we only support for linux with sysfs.
--- qga/commands-posix.c | 4 +++- qga/commands-win32.c | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-)
qga/commands-posix.c +3 -1
@@ -2228,7 +2228,9 @@ GList *ga_command_blacklist_init(GList *blacklist)const char *list[] = {"guest-suspend-disk" ,"guest-suspend-ram" ,"guest-suspend-hybrid" ,"guest-network-get-interfaces" , -"guest-get-vcpus" ,"guest-set-vcpus" ,NULL }; +"guest-get-vcpus" ,"guest-set-vcpus" , +"guest-get-memory-blocks" ,"guest-set-memory-blocks" , +"guest-get-memory-block-size" ,NULL };char **p = (char **)list;while (*p) {
qga/commands-win32.c +2 -0
@@ -473,6 +473,8 @@ GList *ga_command_blacklist_init(GList *blacklist)"guest-file-write" ,"guest-file-seek" ,"guest-file-flush" ,"guest-suspend-hybrid" ,"guest-network-get-interfaces" ,"guest-get-vcpus" ,"guest-set-vcpus" , +"guest-get-memory-blocks" ,"guest-set-memory-blocks" , +"guest-get-memory-block-size" ,"guest-fsfreeze-freeze-list" ,"guest-get-fsinfo" , "guest-fstrim", NULL};char **p = (char **)list_unsupported;
Signature · 1 line
1.7.12.4
Re: [Qemu-devel] [PATCH RFC for-2.3 6/6] qga: add memory block command that unsupported to blacklist
Quoting zhanghailiang (2014-12-06 00:59:19)
Quoted 3 lines
For memory block command, we only support for linux with sysfs.
Signed-off-by zhanghailiang <[email protected]>
Quoted 35 lines
--- qga/commands-posix.c | 4 +++- qga/commands-win32.c | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-)qga/commands-posix.c +3
-1@@ -2228,7 +2228,9 @@ GList *ga_command_blacklist_init(GList *blacklist)const char *list[] = {"guest-suspend-disk" ,"guest-suspend-ram" ,"guest-suspend-hybrid" ,"guest-network-get-interfaces" , -"guest-get-vcpus" ,"guest-set-vcpus" ,NULL }; +"guest-get-vcpus" ,"guest-set-vcpus" , +"guest-get-memory-blocks" ,"guest-set-memory-blocks" , +"guest-get-memory-block-size" ,NULL };char **p = (char **)list;while (*p) {qga/commands-win32.c +2
-0@@ -473,6 +473,8 @@ GList *ga_command_blacklist_init(GList *blacklist)"guest-file-write" ,"guest-file-seek" ,"guest-file-flush" ,"guest-suspend-hybrid" ,"guest-network-get-interfaces" ,"guest-get-vcpus" ,"guest-set-vcpus" , +"guest-get-memory-blocks" ,"guest-set-memory-blocks" , +"guest-get-memory-block-size" ,"guest-fsfreeze-freeze-list" ,"guest-get-fsinfo" , "guest-fstrim", NULL};char **p = (char **)list_unsupported;Signature · 1 line
1.7.12.4
Ping... ;)
Quoted 23 lines · zhanghailiang
Hi,
This patch series add three guest commands about memory block:
guest-get-memory-blocks, guest-set-memory-blocks, guest-get-memory-block-size.With these three commands, we can get information about guest's memory block online/offline status and memory block size (unit of memory online/offline operation ). Also, we can change guest's memory block status (Logical memory hotplug/unplug) from host.
zhanghailiang (6):
qga: introduce three guest memory block commands with stubs
qga: introduce three help functions for memory block functions
qga: implementqmp_guest_get_memory_blocks()for Linux with sysfs
qga: implementqmp_guest_set_memory_blocks()for Linux with sysfs
qga: implementqmp_guest_get_memory_block_size()for Linux with sysfs
qga: add memory block command that unsupported to blacklistqga/commands-posix.c | 266 ++++++++++++++++++++++++++++++++++++++++++++++++++- qga/commands-win32.c | 21 ++++ qga/qapi-schema.json | 88 +++++++++++++++++ 3 files changed, 374 insertions(+), 1 deletion(-)
Ping again...
Any comments are warmly welcome! Thanks.
Quoted 23 lines · zhanghailiang
Hi,
This patch series add three guest commands about memory block:
guest-get-memory-blocks, guest-set-memory-blocks, guest-get-memory-block-size.With these three commands, we can get information about guest's memory block online/offline status and memory block size (unit of memory online/offline operation ). Also, we can change guest's memory block status (Logical memory hotplug/unplug) from host.
zhanghailiang (6):
qga: introduce three guest memory block commands with stubs
qga: introduce three help functions for memory block functions
qga: implementqmp_guest_get_memory_blocks()for Linux with sysfs
qga: implementqmp_guest_set_memory_blocks()for Linux with sysfs
qga: implementqmp_guest_get_memory_block_size()for Linux with sysfs
qga: add memory block command that unsupported to blacklistqga/commands-posix.c | 266 ++++++++++++++++++++++++++++++++++++++++++++++++++- qga/commands-win32.c | 21 ++++ qga/qapi-schema.json | 88 +++++++++++++++++ 3 files changed, 374 insertions(+), 1 deletion(-)