Tools: New ACRNCTL command "blkrescan"
This patch adds support for new acrnctl command blkrescan. Purpose: To add a virtio-blk device to guest VM after launch. Use case: 1. Anticipate number of block devices that will be needed and add empty backend file while launching VM. e.g: -s 5, virtio-blk,nodisk 2. Use the following acrnctl command to trigger a rescan of virtio-blk device by guest VM, to revalidate and update the backend file. “acrnctl blkrescan VMname slot,newfilepath” v5 -> v6: - Removed unsed #define - Reduced the size of param len of blkrescan command from 512 to 256. v2 -> v5: - No change v1 -> v2: - Renamed the acrnctl command and APIs from diskplug to blkrescan. - Split the patch into two. This corresponds to changes in tools. Tracked-On: #3051 Signed-off-by: Vijay Dhanraj <vijay.dhanraj@intel.com> Reviewed-by: Yu Wang <yu1.wang@intel.com>
This commit is contained in:
parent
30de7e8e34
commit
f178788d7c
|
@ -19,11 +19,18 @@
|
|||
#define ACRN_DM_BASE_PATH "/run/acrn"
|
||||
#define ACRN_DM_SOCK_PATH "/run/acrn/mngr"
|
||||
|
||||
/* TODO: Revisit PARAM_LEN and see if size can be reduced */
|
||||
#define PARAM_LEN 256
|
||||
|
||||
struct mngr_msg {
|
||||
unsigned long long magic; /* Make sure you get a mngr_msg */
|
||||
unsigned int msgid;
|
||||
unsigned long timestamp;
|
||||
union {
|
||||
|
||||
/* Arguments to rescan virtio-blk device */
|
||||
char devargs[PARAM_LEN];
|
||||
|
||||
/* ack of DM_STOP, DM_SUSPEND, DM_RESUME, DM_PAUSE, DM_CONTINUE,
|
||||
ACRND_TIMER, ACRND_STOP, ACRND_RESUME, RTC_TIMER */
|
||||
int err;
|
||||
|
@ -82,6 +89,7 @@ enum dm_msgid {
|
|||
DM_PAUSE, /* Freeze this virtual machine */
|
||||
DM_CONTINUE, /* Unfreeze this virtual machine */
|
||||
DM_QUERY, /* Ask power state of this UOS */
|
||||
DM_BLKRESCAN, /* Rescan virtio-blk device for any changes in UOS */
|
||||
DM_MAX,
|
||||
};
|
||||
|
||||
|
|
|
@ -456,3 +456,22 @@ int resume_vm(const char *vmname, unsigned reason)
|
|||
|
||||
return ack.data.err;
|
||||
}
|
||||
|
||||
int blkrescan_vm(const char *vmname, char *devargs)
|
||||
{
|
||||
struct mngr_msg req;
|
||||
struct mngr_msg ack;
|
||||
|
||||
req.magic = MNGR_MSG_MAGIC;
|
||||
req.msgid = DM_BLKRESCAN;
|
||||
req.timestamp = time(NULL);
|
||||
strncpy(req.data.devargs, devargs, strlen(devargs)+1);
|
||||
|
||||
send_msg(vmname, &req, &ack);
|
||||
|
||||
if (ack.data.err) {
|
||||
printf("Unable to rescan virtio-blk device in vm. errno(%d)\n", ack.data.err);
|
||||
}
|
||||
|
||||
return ack.data.err;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* ProjectAcrn
|
||||
* ProjectAcrn
|
||||
* Acrnctl
|
||||
*
|
||||
* Copyright (C) 2018 Intel Corporation. All rights reserved.
|
||||
|
@ -37,6 +37,10 @@
|
|||
#define SUSPEND_DESC "Switch virtual machine to suspend state"
|
||||
#define RESUME_DESC "Resume virtual machine from suspend state"
|
||||
#define RESET_DESC "Stop and then start virtual machine VM_NAME"
|
||||
#define BLKRESCAN_DESC "Rescan virtio-blk device attached to a virtual machine"
|
||||
|
||||
#define VM_NAME (1)
|
||||
#define CMD_ARGS (2)
|
||||
|
||||
#define STOP_TIMEOUT 30U
|
||||
|
||||
|
@ -415,6 +419,26 @@ static int acrnctl_do_add(int argc, char *argv[])
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int acrnctl_do_blkrescan(int argc, char *argv[])
|
||||
{
|
||||
struct vmmngr_struct *s;
|
||||
|
||||
s = vmmngr_find(argv[VM_NAME]);
|
||||
if (!s) {
|
||||
printf("can't find %s\n", argv[VM_NAME]);
|
||||
return -1;
|
||||
}
|
||||
if (s->state != VM_STARTED) {
|
||||
printf("%s is in %s state but should be in %s state for blockrescan\n",
|
||||
argv[VM_NAME], state_str[s->state], state_str[VM_STARTED]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
blkrescan_vm(argv[VM_NAME], argv[CMD_ARGS]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int acrnctl_do_stop(int argc, char *argv[])
|
||||
{
|
||||
struct vmmngr_struct *s;
|
||||
|
@ -702,6 +726,18 @@ int df_valid_args(struct acrnctl_cmd *cmd, int argc, char *argv[])
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int valid_blkrescan_args(struct acrnctl_cmd *cmd, int argc, char *argv[])
|
||||
{
|
||||
char df_opt[] = "VM_NAME slot,newpath";
|
||||
|
||||
if (argc != 3 || !strcmp(argv[1], "help")) {
|
||||
printf("acrnctl %s %s\n", cmd->cmd, df_opt);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int valid_add_args(struct acrnctl_cmd *cmd, int argc, char *argv[])
|
||||
{
|
||||
char df_opt[32] = "launch_scripts options";
|
||||
|
@ -747,6 +783,7 @@ struct acrnctl_cmd acmds[] = {
|
|||
ACMD("suspend", acrnctl_do_suspend, SUSPEND_DESC, df_valid_args),
|
||||
ACMD("resume", acrnctl_do_resume, RESUME_DESC, df_valid_args),
|
||||
ACMD("reset", acrnctl_do_reset, RESET_DESC, df_valid_args),
|
||||
ACMD("blkrescan", acrnctl_do_blkrescan, BLKRESCAN_DESC, valid_blkrescan_args),
|
||||
};
|
||||
|
||||
#define NCMD (sizeof(acmds)/sizeof(struct acrnctl_cmd))
|
||||
|
|
|
@ -59,5 +59,6 @@ int pause_vm(const char *vmname);
|
|||
int continue_vm(const char *vmname);
|
||||
int suspend_vm(const char *vmname);
|
||||
int resume_vm(const char *vmname, unsigned reason);
|
||||
int blkrescan_vm(const char *vmname, char *devargs);
|
||||
|
||||
#endif /* _ACRNCTL_H_ */
|
||||
|
|
Loading…
Reference in New Issue