From mboxrd@z Thu Jan 1 00:00:00 1970 From: Anthony Liguori Subject: Re: [PATCH 1/4][RFC] Allow storing arbitrary annotations in qcow2 images Date: Wed, 08 Aug 2007 14:47:08 -0500 Message-ID: <46BA1DBC.4050307@codemonkey.ws> References: <59abf66e0708081121s56fc2c01vb762850b6f5eeb7a@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org To: =?ISO-8859-1?Q?Jorge_Luc=E1ngeli_Obes?= Return-path: In-Reply-To: <59abf66e0708081121s56fc2c01vb762850b6f5eeb7a-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org Errors-To: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org List-Id: kvm.vger.kernel.org This should go through qemu-devel BTW. Please submit there and I'll = provide comments. Regards, Anthony Liguori Jorge Luc=E1ngeli Obes wrote: > This patch adds an extra 'annot' field to qcow2 snapshots, and updates > serialization functions. > > Signed-off-by: Jorge Luc=E1ngeli Obes > --- > diff --git a/qemu/block-qcow2.c b/qemu/block-qcow2.c > index 0f7a069..361d300 100644 > --- a/qemu/block-qcow2.c > +++ b/qemu/block-qcow2.c > @@ -106,6 +106,8 @@ typedef struct QCowSnapshot { > uint32_t l1_size; > char *id_str; > char *name; > + char *annot; > + > uint32_t vm_state_size; > uint32_t date_sec; > uint32_t date_nsec; > @@ -1370,6 +1372,7 @@ static void qcow_free_snapshots(BlockDriverState *b= s) > for(i =3D 0; i < s->nb_snapshots; i++) { > qemu_free(s->snapshots[i].name); > qemu_free(s->snapshots[i].id_str); > + qemu_free(s->snapshots[i].annot); > } > qemu_free(s->snapshots); > s->snapshots =3D NULL; > @@ -1401,12 +1404,18 @@ static int qcow_read_snapshots(BlockDriverState *= bs) > sn->date_sec =3D be32_to_cpu(h.date_sec); > sn->date_nsec =3D be32_to_cpu(h.date_nsec); > sn->vm_clock_nsec =3D be64_to_cpu(h.vm_clock_nsec); > - extra_data_size =3D be32_to_cpu(h.extra_data_size); > > + extra_data_size =3D be32_to_cpu(h.extra_data_size); > id_str_size =3D be16_to_cpu(h.id_str_size); > name_size =3D be16_to_cpu(h.name_size); > > + sn->annot =3D qemu_malloc(extra_data_size + 1); > + if (!sn->annot) > + goto fail; > + if (bdrv_pread(s->hd, offset, sn->annot, extra_data_size) !=3D > extra_data_size) > + goto fail; > offset +=3D extra_data_size; > + sn->annot[extra_data_size] =3D '\0'; > > sn->id_str =3D qemu_malloc(id_str_size + 1); > if (!sn->id_str) > @@ -1439,7 +1448,7 @@ static int qcow_write_snapshots(BlockDriverState *b= s) > QCowSnapshotHeader h; > int i, name_size, id_str_size, snapshots_size; > uint64_t data64; > - uint32_t data32; > + uint32_t data32, extra_data_size; > int64_t offset, snapshots_offset; > > /* compute the size of the snapshots */ > @@ -1448,6 +1457,7 @@ static int qcow_write_snapshots(BlockDriverState *b= s) > sn =3D s->snapshots + i; > offset =3D align_offset(offset, 8); > offset +=3D sizeof(h); > + offset +=3D strlen(sn->annot); > offset +=3D strlen(sn->id_str); > offset +=3D strlen(sn->name); > } > @@ -1455,7 +1465,7 @@ static int qcow_write_snapshots(BlockDriverState *b= s) > > snapshots_offset =3D alloc_clusters(bs, snapshots_size); > offset =3D snapshots_offset; > - > + > for(i =3D 0; i < s->nb_snapshots; i++) { > sn =3D s->snapshots + i; > memset(&h, 0, sizeof(h)); > @@ -1465,7 +1475,9 @@ static int qcow_write_snapshots(BlockDriverState *b= s) > h.date_sec =3D cpu_to_be32(sn->date_sec); > h.date_nsec =3D cpu_to_be32(sn->date_nsec); > h.vm_clock_nsec =3D cpu_to_be64(sn->vm_clock_nsec); > - > + > + extra_data_size =3D strlen(sn->annot); > + h.extra_data_size =3D cpu_to_be32(extra_data_size); > id_str_size =3D strlen(sn->id_str); > name_size =3D strlen(sn->name); > h.id_str_size =3D cpu_to_be16(id_str_size); > @@ -1474,6 +1486,9 @@ static int qcow_write_snapshots(BlockDriverState *b= s) > if (bdrv_pwrite(s->hd, offset, &h, sizeof(h)) !=3D sizeof(h)) > goto fail; > offset +=3D sizeof(h); > + if (bdrv_pwrite(s->hd, offset, sn->annot, extra_data_size) !=3D > extra_data_size) > + goto fail; > + offset +=3D extra_data_size; > if (bdrv_pwrite(s->hd, offset, sn->id_str, id_str_size) !=3D id_= str_size) > goto fail; > offset +=3D id_str_size; > @@ -1570,6 +1585,10 @@ static int qcow_snapshot_create(BlockDriverState *= bs, > sn->name =3D qemu_strdup(sn_info->name); > if (!sn->name) > goto fail; > + sn->annot =3D qemu_strdup(sn_info->annot); > + if (!sn->annot) > + goto fail; > + > sn->vm_state_size =3D sn_info->vm_state_size; > sn->date_sec =3D sn_info->date_sec; > sn->date_nsec =3D sn_info->date_nsec; > @@ -1680,6 +1699,8 @@ static int qcow_snapshot_delete(BlockDriverState > *bs, const char *snapshot_id) > > qemu_free(sn->id_str); > qemu_free(sn->name); > + qemu_free(sn->annot); > + > memmove(sn, sn + 1, (s->nb_snapshots - snapshot_index - 1) * sizeof(= *sn)); > s->nb_snapshots--; > ret =3D qcow_write_snapshots(bs); > @@ -1707,10 +1728,14 @@ static int qcow_snapshot_list(BlockDriverState *b= s, > for(i =3D 0; i < s->nb_snapshots; i++) { > sn_info =3D sn_tab + i; > sn =3D s->snapshots + i; > + > pstrcpy(sn_info->id_str, sizeof(sn_info->id_str), > sn->id_str); > pstrcpy(sn_info->name, sizeof(sn_info->name), > sn->name); > + pstrcpy(sn_info->annot, sizeof(sn_info->annot), > + sn->annot); > + > sn_info->vm_state_size =3D sn->vm_state_size; > sn_info->date_sec =3D sn->date_sec; > sn_info->date_nsec =3D sn->date_nsec; > diff --git a/qemu/vl.h b/qemu/vl.h > index 43f56bd..f0273fd 100644 > --- a/qemu/vl.h > +++ b/qemu/vl.h > @@ -589,6 +589,7 @@ typedef struct QEMUSnapshotInfo { > /* the following fields are informative. They are not needed for > the consistency of the snapshot */ > char name[256]; /* user choosen name */ > + char annot[1024]; /* extra info, will be used to store > command-line parameters */ > uint32_t vm_state_size; /* VM state info size */ > uint32_t date_sec; /* UTC date of the snapshot */ > uint32_t date_nsec; > @@ -631,6 +632,7 @@ int bdrv_pread(BlockDriverState *bs, int64_t offset, > int bdrv_pwrite(BlockDriverState *bs, int64_t offset, > const void *buf, int count); > int bdrv_truncate(BlockDriverState *bs, int64_t offset); > + > int64_t bdrv_getlength(BlockDriverState *bs); > void bdrv_get_geometry(BlockDriverState *bs, int64_t *nb_sectors_ptr); > int bdrv_commit(BlockDriverState *bs); > @@ -714,6 +716,12 @@ void path_combine(char *dest, int dest_size, > const char *base_path, > const char *filename); > > +/* annotations */ > +int bdrv_snapshot_annotated(QEMUSnapshotInfo *sn_info); > +int bdrv_set_annot(BlockDriverState *bs, const char *name, > + const char *annotation); > +char *bdrv_get_annot(BlockDriverState *bs, const char *name); > + > #ifndef QEMU_TOOL > > typedef void QEMUMachineInitFunc(int ram_size, int vga_ram_size, > = > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > ------------------------------------------------------------------------ > > _______________________________________________ > kvm-devel mailing list > kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org > https://lists.sourceforge.net/lists/listinfo/kvm-devel ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/