kvm tools: dynamically allocate p9 fids
PATCH 1/1 kvm tools: dynamically allocate p9 fids
This removes the limit for p9 fids and the huge fid array that came along with it. Instead, it dynamically allocates fids and stores them in a rb-tree.
This is useful when the guest needs a lot of fids, such as when stress testing guests.
--- tools/kvm/include/kvm/virtio-9p.h | 5 +- tools/kvm/virtio/9p.c | 149 ++++++++++++++++++++++++++---------- 2 files changed, 110 insertions(+), 44 deletions(-)
tools/kvm/include/kvm/virtio-9p.h +3 -2
@@ -7,12 +7,12 @@#include <sys/types.h> #include <dirent.h> #include <linux/list.h> +#include <linux/rbtree.h> #define NUM_VIRT_QUEUES 1#define VIRTQUEUE_NUM 128#define VIRTIO_9P_DEFAULT_TAG "kvm_9p"#define VIRTIO_9P_HDR_LEN (sizeof(u32)+sizeof(u8)+sizeof(u16)) -#define VIRTIO_9P_MAX_FID 16384#define VIRTIO_9P_VERSION_DOTL "9P2000.L"#define MAX_TAG_LEN 32
@@ -31,6 +31,7 @@ struct p9_fid {char *path;DIR *dir;int fd; +struct rb_node node; };struct p9_dev_job {
@@ -42,6 +43,7 @@ struct p9_dev_job {struct p9_dev {struct list_head list;struct virtio_device vdev; +struct rb_root fids;struct virtio_9p_config *config;u32 features;
@@ -49,7 +51,6 @@ struct p9_dev {/* virtio queue */ struct virt_queue vqs[NUM_VIRT_QUEUES ];struct p9_dev_job jobs[NUM_VIRT_QUEUES ]; -struct p9_fid fids[VIRTIO_9P_MAX_FID ];char root_dir[PATH_MAX ]; };
tools/kvm/virtio/9p.c +107 -42
240 lines not on this page · raw message
Signature · 1 line
1.7.8.6
PATCH 1/1 kvm tools: support injecting arbitrary sysrqs
Add support to 'lkvm debug' to inject arbitrary sysrqs using a new '-s <sysrq>' argument.
--- tools/kvm/builtin-debug.c | 7 +++++++ tools/kvm/builtin-run.c | 5 ++++- tools/kvm/hw/serial.c | 7 +++---- tools/kvm/include/kvm/8250-serial.h | 2 +- tools/kvm/include/kvm/builtin-debug.h | 2 ++ 5 files changed, 17 insertions(+), 6 deletions(-)
tools/kvm/builtin-debug.c +7 -0
@@ -16,6 +16,7 @@ static bool all;static int nmi =-1 ;static bool dump;static const char *instance_name; +static const char *sysrq;static const char *const debug_usage[] = {"lkvm debug [--all] [-n name] [-d] [-m vcpu]" ,
@@ -26,6 +27,7 @@ static const struct option debug_options[] = {OPT_GROUP ("General options:" ),OPT_BOOLEAN ('d' ,"dump" , &dump,"Generate a debug dump from guest" ),OPT_INTEGER ('m' ,"nmi" , &nmi,"Generate NMI on VCPU" ), +OPT_STRING ('s' ,"sysrq" , &sysrq,"sysrq" ,"Inject a sysrq" ),OPT_GROUP ("Instance options:" ),OPT_BOOLEAN ('a' ,"all" , &all,"Debug all instances" ), OPT_STRING('n', "name", &instance_name, "name", "Instance name"),
@@ -61,6 +63,11 @@ static int do_debug(const char *name, int sock) cmd.cpu = nmi; } +if (sysrq) { + cmd.dbg_type |=KVM_DEBUG_CMD_TYPE_SYSRQ ; + cmd.sysrq = sysrq[0 ]; + } + r =kvm_ipc__send_msg (sock,KVM_IPC_DEBUG ,sizeof (cmd), (u8 *)&cmd);if (r <0 )return r;
tools/kvm/builtin-run.c +4 -1
@@ -557,6 +557,9 @@ static void handle_debug(int fd, u32 type, u32 len, u8 *msg) dbg_type = params->dbg_type; vcpu = params->cpu; +if (dbg_type &KVM_DEBUG_CMD_TYPE_SYSRQ ) +serial8250__inject_sysrq (kvm, params->sysrq); +if (dbg_type &KVM_DEBUG_CMD_TYPE_NMI ) {if ((int )vcpu >= kvm->nrcpus)return ;
@@ -589,7 +592,7 @@ static void handle_debug(int fd, u32 type, u32 len, u8 *msg)close (fd); -serial8250__inject_sysrq (kvm); +serial8250__inject_sysrq (kvm,'p' ); }static void handle_sigalrm (int sig)
tools/kvm/hw/serial.c +3 -4
@@ -153,14 +153,13 @@ static void serial8250_update_irq(struct kvm *kvm, struct serial8250_device *dev }#define SYSRQ_PENDING_NONE 0 -#define SYSRQ_PENDING_BREAK 1static int sysrq_pending;static void serial8250__sysrq (struct kvm *kvm,struct serial8250_device *dev) { dev->lsr |=UART_LSR_DR |UART_LSR_BI ; - dev->rxbuf[dev->rxcnt++] ='p' ; + dev->rxbuf[dev->rxcnt++] = sysrq_pending; sysrq_pending =SYSRQ_PENDING_NONE ; }
@@ -219,9 +218,9 @@ void serial8250__update_consoles(struct kvm *kvm) } } -void serial8250__inject_sysrq (struct kvm *kvm) +void serial8250__inject_sysrq (struct kvm *kvm,char sysrq) { - sysrq_pending =SYSRQ_PENDING_BREAK ; + sysrq_pending = sysrq; }static struct serial8250_device *find_device (u16 port)
tools/kvm/include/kvm/8250-serial.h +1 -1
@@ -6,6 +6,6 @@ struct kvm;int serial8250__init (struct kvm *kvm);int serial8250__exit (struct kvm *kvm);void serial8250__update_consoles (struct kvm *kvm); -void serial8250__inject_sysrq (struct kvm *kvm); +void serial8250__inject_sysrq (struct kvm *kvm,char sysrq);#endif /* KVM__8250_SERIAL_H */
tools/kvm/include/kvm/builtin-debug.h +2 -0
@@ -6,10 +6,12 @@#define KVM_DEBUG_CMD_TYPE_DUMP (1 << 0)#define KVM_DEBUG_CMD_TYPE_NMI (1 << 1) +#define KVM_DEBUG_CMD_TYPE_SYSRQ (1 << 2)struct debug_cmd_params {u32 dbg_type;u32 cpu; +char sysrq; };int kvm_cmd_debug (int argc,const char **argv,const char *prefix);
Signature · 1 line
1.7.8.6
PATCH 1/1 kvm tools: remove unused field from virtio-blk
In reply to Sasha Levin--- tools/kvm/virtio/blk.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
tools/kvm/virtio/blk.c +0 -1
@@ -40,7 +40,6 @@ struct blk_dev {pthread_mutex_t mutex;struct list_head list; -struct list_head req_list;struct virtio_device vdev;struct virtio_blk_config blk_config;
Signature · 1 line
1.7.8.6
PATCH 1/1 kvm tools: use correct error value for virtio-9p RLERROR
In reply to Sasha LevinRLERROR expects positive error values, passing negative values causes guest kernel panic.
--- tools/kvm/virtio/9p.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
tools/kvm/virtio/9p.c +1 -1
@@ -548,7 +548,7 @@ static void virtio_p9_readdir(struct p9_dev *p9dev, fid =get_fid (p9dev, fid_val);if (!fid->is_dir) { - errno = -EINVAL ; + errno =EINVAL ; goto err_out; }
Signature · 1 line
1.7.8.6
PATCH 1/1 kvm tools: don't bother tracking is_dir
In reply to Sasha LevinThis is something we can calculate on the fly, and doesn't justify the overhead of tracking it all over fid transitions.
--- tools/kvm/include/kvm/virtio-9p.h | 1 - tools/kvm/virtio/9p.c | 16 +++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-)
tools/kvm/include/kvm/virtio-9p.h +0 -1
@@ -26,7 +26,6 @@ struct p9_msg {struct p9_fid {u32 fid;u32 uid; -u8 is_dir;char abs_path[PATH_MAX ];char *path;DIR *dir;
tools/kvm/virtio/9p.c +11 -5
@@ -228,6 +228,15 @@ static int virtio_p9_openflags(int flags)return flags; } +static bool is_dir (struct p9_fid *fid) +{ +struct stat st; + +stat (fid->abs_path, &st); + +return S_ISDIR (st.st_mode); +} +static void virtio_p9_open (struct p9_dev *p9dev,struct p9_pdu *pdu,u32 *outlen) {
@@ -245,7 +254,7 @@ static void virtio_p9_open(struct p9_dev *p9dev,stat2qid (&st, &qid); -if (new_fid->is_dir) { +if (is_dir (new_fid)) { new_fid->dir =opendir (new_fid->abs_path);if (!new_fid->dir) goto err_out;
@@ -394,7 +403,6 @@ static void virtio_p9_walk(struct p9_dev *p9dev, goto err_out;stat2qid (&st, &wqid); - new_fid->is_dir =S_ISDIR (st.st_mode);strcpy (new_fid->path, tmp); new_fid->uid = fid->uid; nwqid++;
@@ -406,7 +414,6 @@ static void virtio_p9_walk(struct p9_dev *p9dev,*/ pdu->write_offset +=sizeof (u16); old_fid =get_fid (p9dev, fid_val); - new_fid->is_dir = old_fid->is_dir;strcpy (new_fid->path, old_fid->path); new_fid->uid = old_fid->uid; }
@@ -445,7 +452,6 @@ static void virtio_p9_attach(struct p9_dev *p9dev, fid =get_fid (p9dev, fid_val); fid->uid = uid; - fid->is_dir =1 ;strcpy (fid->path,"/" );virtio_p9_pdu_writef (pdu,"Q" , &qid);
@@ -547,7 +553,7 @@ static void virtio_p9_readdir(struct p9_dev *p9dev,virtio_p9_pdu_readf (pdu,"dqd" , &fid_val, &offset, &count); fid =get_fid (p9dev, fid_val); -if (!fid->is_dir) { +if (!is_dir (fid)) { errno =EINVAL ; goto err_out; }
Signature · 1 line
1.7.8.6
Re: [PATCH] kvm tools: don't bother tracking is_dir
Quoted 4 lines · Sasha Levin
This is something we can calculate on the fly, and doesn't justify the overhead of tracking it all over fid transitions.
Signed-off-by Sasha Levin <[email protected]>
What kind of overhead are you talking about?
Quoted 83 lines
--- tools/kvm/include/kvm/virtio-9p.h | 1 - tools/kvm/virtio/9p.c | 16 +++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-)tools/kvm/include/kvm/virtio-9p.h +0
-1@@ -26,7 +26,6 @@ struct p9_msg {struct p9_fid {u32 fid;u32 uid; -u8 is_dir;char abs_path[PATH_MAX ];char *path;DIR *dir;tools/kvm/virtio/9p.c +11
-5@@ -228,6 +228,15 @@ static int virtio_p9_openflags(int flags)return flags; } +static bool is_dir (struct p9_fid *fid) +{ +struct stat st; + +stat (fid->abs_path, &st); + +return S_ISDIR (st.st_mode); +} +static void virtio_p9_open (struct p9_dev *p9dev,struct p9_pdu *pdu,u32 *outlen) {@@ -245,7 +254,7 @@ static void virtio_p9_open(struct p9_dev *p9dev,stat2qid (&st, &qid); -if (new_fid->is_dir) { +if (is_dir (new_fid)) { new_fid->dir =opendir (new_fid->abs_path);if (!new_fid->dir) goto err_out;@@ -394,7 +403,6 @@ static void virtio_p9_walk(struct p9_dev *p9dev, goto err_out;stat2qid (&st, &wqid); - new_fid->is_dir =S_ISDIR (st.st_mode);strcpy (new_fid->path, tmp); new_fid->uid = fid->uid; nwqid++;@@ -406,7 +414,6 @@ static void virtio_p9_walk(struct p9_dev *p9dev,*/ pdu->write_offset +=sizeof (u16); old_fid =get_fid (p9dev, fid_val); - new_fid->is_dir = old_fid->is_dir;strcpy (new_fid->path, old_fid->path); new_fid->uid = old_fid->uid; }@@ -445,7 +452,6 @@ static void virtio_p9_attach(struct p9_dev *p9dev, fid =get_fid (p9dev, fid_val); fid->uid = uid; - fid->is_dir =1 ;strcpy (fid->path,"/" );virtio_p9_pdu_writef (pdu,"Q" , &qid);@@ -547,7 +553,7 @@ static void virtio_p9_readdir(struct p9_dev *p9dev,virtio_p9_pdu_readf (pdu,"dqd" , &fid_val, &offset, &count); fid =get_fid (p9dev, fid_val); -if (!fid->is_dir) { +if (!is_dir (fid)) { errno =EINVAL ; goto err_out; }Signature · 1 line
1.7.8.6
Re: [PATCH] kvm tools: don't bother tracking is_dir
Quoted 7 lines · Pekka Enberg
Quoted 4 lines · Sasha Levin
This is something we can calculate on the fly, and doesn't justify the overhead of tracking it all over fid transitions.
Signed-off-by Sasha Levin <[email protected]>What kind of overhead are you talking about?
Having to carry it between fids when they are copied/created.
This flag is required in only about 2-3 spots, and I've stumbled on a bunch of issues when writing the dynamic fid allocation due to failure to copy this flag over only when required.