From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58824) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XYiqQ-0006NE-P6 for qemu-devel@nongnu.org; Mon, 29 Sep 2014 17:51:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XYiqK-0001ie-1J for qemu-devel@nongnu.org; Mon, 29 Sep 2014 17:50:58 -0400 Received: from lputeaux-656-01-25-125.w80-12.abo.wanadoo.fr ([80.12.84.125]:53166 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XYiqJ-0001i2-No for qemu-devel@nongnu.org; Mon, 29 Sep 2014 17:50:51 -0400 Date: Mon, 29 Sep 2014 23:48:25 +0200 From: =?iso-8859-1?Q?Beno=EEt?= Canet Message-ID: <20140929214825.GB7692@irqsave.net> References: <1411744797-17121-1-git-send-email-boriss@gmail.com> <1411744797-17121-2-git-send-email-boriss@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1411744797-17121-2-git-send-email-boriss@gmail.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 1/2] virtio-9p: Add support for 9p migration. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Boris Sukholitko Cc: qemu-devel@nongnu.org The Friday 26 Sep 2014 =E0 18:19:56 (+0300), Boris Sukholitko wrote : > This patch is a rebase of Aneesh Kumar's and Benoit Canet's previous > work. >=20 > Signed-off-by: Boris Sukholitko If Aneesh and me worked on this you should also keep our signed-off in ad= dition of yours. Best regards Beno=EEt > --- > hw/9pfs/virtio-9p-device.c | 152 +++++++++++++++++++++++++++++++++++++= ++++++++ > 1 file changed, 152 insertions(+) >=20 > diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c > index 2572747..078ad39 100644 > --- a/hw/9pfs/virtio-9p-device.c > +++ b/hw/9pfs/virtio-9p-device.c > @@ -21,6 +21,149 @@ > #include "virtio-9p-coth.h" > #include "hw/virtio/virtio-access.h" > =20 > +static void virtio_9p_save_path(QEMUFile *f, V9fsPath *path) > +{ > + qemu_put_be16(f, path->size); > + qemu_put_buffer(f, (const uint8_t *) path->data, path->size); > +} > + > +static void virtio_9p_save_string(QEMUFile *f, V9fsString *s) > +{ > + qemu_put_be16(f, s->size); > + qemu_put_buffer(f, (const uint8_t *) s->data, s->size); > +} > + > +static void virtio_9p_save_xattr(QEMUFile *f, V9fsXattr *xattr) > +{ > + qemu_put_be64(f, xattr->copied_len); > + qemu_put_be64(f, xattr->len); > + qemu_put_buffer(f, (const uint8_t *) xattr->value, xattr->len); > + virtio_9p_save_string(f, &xattr->name); > + qemu_put_be32(f, xattr->flags); > +} > + > +static void virtio_9p_save_fid(QEMUFile *f, V9fsFidState *fid) > +{ > + /* First close the fid and mark it for reopen if migration fail */ > + if (fid->fid_type =3D=3D P9_FID_FILE) { > + close(fid->fs.fd); > + fid->fs.fd =3D -1; > + } else if (fid->fid_type =3D=3D P9_FID_DIR) { > + closedir(fid->fs.dir); > + fid->fs.dir =3D NULL; > + } > + > + qemu_put_be32(f, fid->fid_type); > + if (fid->fid_type =3D=3D P9_FID_XATTR) { > + /* we don't save fs_reclaim */ > + virtio_9p_save_xattr(f, &fid->fs.xattr); > + } > + qemu_put_be32(f, fid->fid); > + virtio_9p_save_path(f, &fid->path); > + qemu_put_be32(f, fid->flags); > + qemu_put_be32(f, fid->open_flags); > + qemu_put_be32(f, fid->uid); > + qemu_put_be32(f, fid->ref); > + qemu_put_be32(f, fid->clunked); > +} > + > +static void virtio_9p_save(QEMUFile *f, void *opaque) > +{ > + int fidcount =3D 0; > + V9fsState *s =3D opaque; > + V9fsFidState *fid; > + > + virtio_save(VIRTIO_DEVICE(s), f); > + > + for (fid =3D s->fid_list; fid; fid =3D fid->next) { > + fidcount++; > + } > + /* Write the total number of fid structure */ > + qemu_put_be32(f, fidcount); > + > + for (fid =3D s->fid_list; fid; fid =3D fid->next) { > + virtio_9p_save_fid(f, fid); > + } > + > + qemu_put_be32(f, s->proto_version); > + qemu_put_be32(f, s->msize); > +} > + > +static void virtio_9p_load_path(QEMUFile *f, V9fsPath *path) > +{ > + path->size =3D qemu_get_be16(f); > + path->data =3D g_malloc0(path->size); > + qemu_get_buffer(f, (uint8_t *) path->data, path->size); > +} > + > +static void virtio_9p_load_string(QEMUFile *f, V9fsString *s) > +{ > + s->size =3D qemu_get_be16(f); > + s->data =3D g_malloc0(s->size); > + qemu_get_buffer(f, (uint8_t *) s->data, s->size); > +} > + > +static void virtio_9p_load_xattr(QEMUFile *f, V9fsXattr *xattr) > +{ > + xattr->copied_len =3D qemu_get_be64(f); > + xattr->len =3D qemu_get_be64(f); > + qemu_get_buffer(f, (uint8_t *) xattr->value, xattr->len); > + virtio_9p_load_string(f, &xattr->name); > + xattr->flags =3D qemu_get_be32(f); > +} > + > +static V9fsFidState *virtio_9p_load_fid(QEMUFile *f) > +{ > + V9fsFidState *fid; > + fid =3D g_new0(V9fsFidState, 1); > + > + fid->fid_type =3D qemu_get_be32(f); > + if (fid->fid_type =3D=3D P9_FID_XATTR) { > + virtio_9p_load_xattr(f, &fid->fs.xattr); > + } > + fid->fid =3D qemu_get_be32(f); > + virtio_9p_load_path(f, &fid->path); > + fid->flags =3D qemu_get_be32(f); > + fid->open_flags =3D qemu_get_be32(f); > + fid->uid =3D qemu_get_be32(f); > + fid->ref =3D qemu_get_be32(f); > + fid->clunked =3D qemu_get_be32(f); > + > + /* If it's a file fid mark the file descriptors as closed. > + * DIR is null thanks to g_new0. > + * When doing get_fid v9fs_reopen_fid will reopen the file or the = directory. > + */ > + if (fid->fid_type =3D=3D P9_FID_FILE) { > + fid->fs.fd =3D -1; > + } > + return fid; > +} > + > +static int virtio_9p_load(QEMUFile *f, void *opaque, int version_id) > +{ > + int fidcount; > + V9fsState *s =3D opaque; > + V9fsFidState **fid; > + > + if (version_id !=3D 2) { > + return -EINVAL; > + } > + virtio_load(VIRTIO_DEVICE(s), f, version_id); > + fidcount =3D qemu_get_be32(f); > + > + fid =3D &s->fid_list; > + while (fidcount) { > + *fid =3D virtio_9p_load_fid(f); > + fid =3D &((*fid)->next); > + fidcount--; > + } > + > + s->proto_version =3D qemu_get_be32(f); > + s->msize =3D qemu_get_be32(f); > + > + return 0; > +} > + > static uint32_t virtio_9p_get_features(VirtIODevice *vdev, uint32_t fe= atures) > { > features |=3D 1 << VIRTIO_9P_MOUNT_TAG; > @@ -50,6 +193,7 @@ static void virtio_9p_device_realize(DeviceState *de= v, Error **errp) > struct stat stat; > FsDriverEntry *fse; > V9fsPath path; > + static int virtio_9p_id; > =20 > virtio_init(vdev, "virtio-9p", VIRTIO_ID_9P, > sizeof(struct virtio_9p_config) + MAX_TAG_LEN); > @@ -98,6 +242,14 @@ static void virtio_9p_device_realize(DeviceState *d= ev, Error **errp) > s->ops =3D fse->ops; > s->config_size =3D sizeof(struct virtio_9p_config) + len; > s->fid_list =3D NULL; > + > + /* Original patch says that instance id must be derived of tag > + * name. Hash functions do have collisions so why would it be bett= er > + * than an increment ? > + */ > + register_savevm(dev, "virtio-9p", virtio_9p_id++, 2, > + virtio_9p_save, virtio_9p_load, s); > + > qemu_co_rwlock_init(&s->rename_lock); > =20 > if (s->ops->init(&s->ctx) < 0) { > --=20 > 2.0.2 >=20 >=20