diff mbox

[01/40] 9pfs: allocate pdus with g_malloc/g_free

Message ID 1448388091-117282-2-git-send-email-pbonzini@redhat.com
State New
Headers show

Commit Message

Paolo Bonzini Nov. 24, 2015, 6 p.m. UTC
Prepare for moving the allocation to virtqueue_pop.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/9pfs/virtio-9p-device.c |  7 +------
 hw/9pfs/virtio-9p.c        | 10 +++-------
 hw/9pfs/virtio-9p.h        |  2 --
 3 files changed, 4 insertions(+), 15 deletions(-)

Comments

Fam Zheng Nov. 30, 2015, 2:27 a.m. UTC | #1
On Tue, 11/24 19:00, Paolo Bonzini wrote:
> Prepare for moving the allocation to virtqueue_pop.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  hw/9pfs/virtio-9p-device.c |  7 +------
>  hw/9pfs/virtio-9p.c        | 10 +++-------
>  hw/9pfs/virtio-9p.h        |  2 --
>  3 files changed, 4 insertions(+), 15 deletions(-)
> 
> diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
> index e3abcfa..72a93c2 100644
> --- a/hw/9pfs/virtio-9p-device.c
> +++ b/hw/9pfs/virtio-9p-device.c
> @@ -57,7 +57,7 @@ static void virtio_9p_device_realize(DeviceState *dev, Error **errp)
>  {
>      VirtIODevice *vdev = VIRTIO_DEVICE(dev);
>      V9fsState *s = VIRTIO_9P(dev);
> -    int i, len;
> +    int len;
>      struct stat stat;
>      FsDriverEntry *fse;
>      V9fsPath path;
> @@ -65,12 +65,7 @@ static void virtio_9p_device_realize(DeviceState *dev, Error **errp)
>      virtio_init(vdev, "virtio-9p", VIRTIO_ID_9P,
>                  sizeof(struct virtio_9p_config) + MAX_TAG_LEN);
>  
> -    /* initialize pdu allocator */
> -    QLIST_INIT(&s->free_list);
>      QLIST_INIT(&s->active_list);
> -    for (i = 0; i < (MAX_REQ - 1); i++) {
> -        QLIST_INSERT_HEAD(&s->free_list, &s->pdus[i], next);
> -    }
>  
>      s->vq = virtio_add_queue(vdev, MAX_REQ, handle_9p_output);
>  
> diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
> index f972731..747306b 100644
> --- a/hw/9pfs/virtio-9p.c
> +++ b/hw/9pfs/virtio-9p.c
> @@ -565,13 +565,9 @@ static int fid_to_qid(V9fsPDU *pdu, V9fsFidState *fidp, V9fsQID *qidp)
>  
>  static V9fsPDU *alloc_pdu(V9fsState *s)
>  {
> -    V9fsPDU *pdu = NULL;
> +    V9fsPDU *pdu = g_new(V9fsPDU, 1);
>  
> -    if (!QLIST_EMPTY(&s->free_list)) {
> -        pdu = QLIST_FIRST(&s->free_list);
> -        QLIST_REMOVE(pdu, next);
> -        QLIST_INSERT_HEAD(&s->active_list, pdu, next);
> -    }
> +    QLIST_INSERT_HEAD(&s->active_list, pdu, next);
>      return pdu;
>  }

OK, and I think handle_9p_output no longer needs to check the returned pointer.

Fam

>  
> @@ -584,8 +580,8 @@ static void free_pdu(V9fsState *s, V9fsPDU *pdu)
>           */
>          if (!pdu->cancelled) {
>              QLIST_REMOVE(pdu, next);
> -            QLIST_INSERT_HEAD(&s->free_list, pdu, next);
>          }
> +        g_free(pdu);
>      }
>  }
>  
> diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
> index d7a4dc1..1fb4ff9 100644
> --- a/hw/9pfs/virtio-9p.h
> +++ b/hw/9pfs/virtio-9p.h
> @@ -201,8 +201,6 @@ typedef struct V9fsState
>  {
>      VirtIODevice parent_obj;
>      VirtQueue *vq;
> -    V9fsPDU pdus[MAX_REQ];
> -    QLIST_HEAD(, V9fsPDU) free_list;
>      QLIST_HEAD(, V9fsPDU) active_list;
>      V9fsFidState *fid_list;
>      FileOperations *ops;
> -- 
> 1.8.3.1
> 
> 
>
Fam Zheng Nov. 30, 2015, 2:33 a.m. UTC | #2
On Mon, 11/30 10:27, Fam Zheng wrote:
> On Tue, 11/24 19:00, Paolo Bonzini wrote:
> OK, and I think handle_9p_output no longer needs to check the returned pointer.

Yes it's removed in patch 3, good.

Fam
Greg Kurz Nov. 30, 2015, 4:35 p.m. UTC | #3
On Tue, 24 Nov 2015 19:00:52 +0100
Paolo Bonzini <pbonzini@redhat.com> wrote:

> Prepare for moving the allocation to virtqueue_pop.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---

And aside from this series goal, it makes the code nicer :)

>  hw/9pfs/virtio-9p-device.c |  7 +------
>  hw/9pfs/virtio-9p.c        | 10 +++-------
>  hw/9pfs/virtio-9p.h        |  2 --
>  3 files changed, 4 insertions(+), 15 deletions(-)
> 
> diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
> index e3abcfa..72a93c2 100644
> --- a/hw/9pfs/virtio-9p-device.c
> +++ b/hw/9pfs/virtio-9p-device.c
> @@ -57,7 +57,7 @@ static void virtio_9p_device_realize(DeviceState *dev, Error **errp)
>  {
>      VirtIODevice *vdev = VIRTIO_DEVICE(dev);
>      V9fsState *s = VIRTIO_9P(dev);
> -    int i, len;
> +    int len;
>      struct stat stat;
>      FsDriverEntry *fse;
>      V9fsPath path;
> @@ -65,12 +65,7 @@ static void virtio_9p_device_realize(DeviceState *dev, Error **errp)
>      virtio_init(vdev, "virtio-9p", VIRTIO_ID_9P,
>                  sizeof(struct virtio_9p_config) + MAX_TAG_LEN);
> 
> -    /* initialize pdu allocator */
> -    QLIST_INIT(&s->free_list);
>      QLIST_INIT(&s->active_list);
> -    for (i = 0; i < (MAX_REQ - 1); i++) {
> -        QLIST_INSERT_HEAD(&s->free_list, &s->pdus[i], next);
> -    }
> 
>      s->vq = virtio_add_queue(vdev, MAX_REQ, handle_9p_output);
> 
> diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
> index f972731..747306b 100644
> --- a/hw/9pfs/virtio-9p.c
> +++ b/hw/9pfs/virtio-9p.c
> @@ -565,13 +565,9 @@ static int fid_to_qid(V9fsPDU *pdu, V9fsFidState *fidp, V9fsQID *qidp)
> 
>  static V9fsPDU *alloc_pdu(V9fsState *s)
>  {
> -    V9fsPDU *pdu = NULL;
> +    V9fsPDU *pdu = g_new(V9fsPDU, 1);
> 
> -    if (!QLIST_EMPTY(&s->free_list)) {
> -        pdu = QLIST_FIRST(&s->free_list);
> -        QLIST_REMOVE(pdu, next);
> -        QLIST_INSERT_HEAD(&s->active_list, pdu, next);
> -    }
> +    QLIST_INSERT_HEAD(&s->active_list, pdu, next);
>      return pdu;
>  }
> 
> @@ -584,8 +580,8 @@ static void free_pdu(V9fsState *s, V9fsPDU *pdu)
>           */
>          if (!pdu->cancelled) {
>              QLIST_REMOVE(pdu, next);
> -            QLIST_INSERT_HEAD(&s->free_list, pdu, next);
>          }
> +        g_free(pdu);
>      }
>  }
> 
> diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
> index d7a4dc1..1fb4ff9 100644
> --- a/hw/9pfs/virtio-9p.h
> +++ b/hw/9pfs/virtio-9p.h
> @@ -201,8 +201,6 @@ typedef struct V9fsState
>  {
>      VirtIODevice parent_obj;
>      VirtQueue *vq;
> -    V9fsPDU pdus[MAX_REQ];
> -    QLIST_HEAD(, V9fsPDU) free_list;
>      QLIST_HEAD(, V9fsPDU) active_list;
>      V9fsFidState *fid_list;
>      FileOperations *ops;
diff mbox

Patch

diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
index e3abcfa..72a93c2 100644
--- a/hw/9pfs/virtio-9p-device.c
+++ b/hw/9pfs/virtio-9p-device.c
@@ -57,7 +57,7 @@  static void virtio_9p_device_realize(DeviceState *dev, Error **errp)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
     V9fsState *s = VIRTIO_9P(dev);
-    int i, len;
+    int len;
     struct stat stat;
     FsDriverEntry *fse;
     V9fsPath path;
@@ -65,12 +65,7 @@  static void virtio_9p_device_realize(DeviceState *dev, Error **errp)
     virtio_init(vdev, "virtio-9p", VIRTIO_ID_9P,
                 sizeof(struct virtio_9p_config) + MAX_TAG_LEN);
 
-    /* initialize pdu allocator */
-    QLIST_INIT(&s->free_list);
     QLIST_INIT(&s->active_list);
-    for (i = 0; i < (MAX_REQ - 1); i++) {
-        QLIST_INSERT_HEAD(&s->free_list, &s->pdus[i], next);
-    }
 
     s->vq = virtio_add_queue(vdev, MAX_REQ, handle_9p_output);
 
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index f972731..747306b 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -565,13 +565,9 @@  static int fid_to_qid(V9fsPDU *pdu, V9fsFidState *fidp, V9fsQID *qidp)
 
 static V9fsPDU *alloc_pdu(V9fsState *s)
 {
-    V9fsPDU *pdu = NULL;
+    V9fsPDU *pdu = g_new(V9fsPDU, 1);
 
-    if (!QLIST_EMPTY(&s->free_list)) {
-        pdu = QLIST_FIRST(&s->free_list);
-        QLIST_REMOVE(pdu, next);
-        QLIST_INSERT_HEAD(&s->active_list, pdu, next);
-    }
+    QLIST_INSERT_HEAD(&s->active_list, pdu, next);
     return pdu;
 }
 
@@ -584,8 +580,8 @@  static void free_pdu(V9fsState *s, V9fsPDU *pdu)
          */
         if (!pdu->cancelled) {
             QLIST_REMOVE(pdu, next);
-            QLIST_INSERT_HEAD(&s->free_list, pdu, next);
         }
+        g_free(pdu);
     }
 }
 
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index d7a4dc1..1fb4ff9 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -201,8 +201,6 @@  typedef struct V9fsState
 {
     VirtIODevice parent_obj;
     VirtQueue *vq;
-    V9fsPDU pdus[MAX_REQ];
-    QLIST_HEAD(, V9fsPDU) free_list;
     QLIST_HEAD(, V9fsPDU) active_list;
     V9fsFidState *fid_list;
     FileOperations *ops;