From patchwork Tue Feb 12 13:06:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 2128341 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id A6696DFB7B for ; Tue, 12 Feb 2013 13:08:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933202Ab3BLNGs (ORCPT ); Tue, 12 Feb 2013 08:06:48 -0500 Received: from mail-ve0-f178.google.com ([209.85.128.178]:40720 "EHLO mail-ve0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932967Ab3BLNGq (ORCPT ); Tue, 12 Feb 2013 08:06:46 -0500 Received: by mail-ve0-f178.google.com with SMTP id db10so42126veb.9 for ; Tue, 12 Feb 2013 05:06:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=8gxjsXk8UO9zmZf5yfcZIJhKZpozsMgg4BVob8bxY2Y=; b=TtP0J9NEvFMNBBdiT0ANMi47zacFQPjMMhqIQ4bu/shglO686J2bo2bRQtVb6+d7dT /U9cp6+/tIXaFihjoFp6IeR7pFlULr5x4BNjRuKCtO63mox7zrBY6VrnLZ10FXAvYv1S Z/5K25CP8K0G4hyfE5/9aNo5QVJ685uFTxMhr34URdNWVknV1PXEX5XykxTwfzzfQlUx bfJQqRmZymS1Cao0zAxw4RLv3FPyBIzz5v+GWzRTmigIifm7zXJvrnZYtVpbiJhQynIn v2Q8iYta0J7wmfs20nmpG6u8gFffsrxnVvQDSnFGqknZXrIWNHSD40f7mAJVgqxkfzYX sT1w== X-Received: by 10.52.97.7 with SMTP id dw7mr20534825vdb.38.1360674405331; Tue, 12 Feb 2013 05:06:45 -0800 (PST) Received: from yakj.usersys.redhat.com (93-34-179-137.ip50.fastwebnet.it. [93.34.179.137]) by mx.google.com with ESMTPS id qj8sm64158235veb.2.2013.02.12.05.06.42 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 12 Feb 2013 05:06:44 -0800 (PST) From: Paolo Bonzini To: linux-kernel@vger.kernel.org Cc: Wanlong Gao , asias@redhat.com, mst@redhat.com, Rusty Russell , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, JBottomley@parallels.com, linux-scsi@vger.kernel.org Subject: [PATCH v3 1/5] virtio-scsi: redo allocation of target data Date: Tue, 12 Feb 2013 14:06:27 +0100 Message-Id: <1360674391-2661-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1360674391-2661-1-git-send-email-pbonzini@redhat.com> References: <1360674391-2661-1-git-send-email-pbonzini@redhat.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org virtio_scsi_target_state is now empty, but we will find new uses for it in the next few patches. However, dropping the sglist lets us turn the array-of-pointers into a simple array, which simplifies the allocation. However, we do not leave the virtio_scsi_target_state structs in the flexible array member at the end of struct virtio_scsi, because we will place the virtqueues there in the next patches. Cc: linux-scsi@vger.kernel.org Signed-off-by: Paolo Bonzini --- drivers/scsi/virtio_scsi.c | 39 ++++++++++++--------------------------- 1 files changed, 12 insertions(+), 27 deletions(-) diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c index 8b90c17..3f15568 100644 --- a/drivers/scsi/virtio_scsi.c +++ b/drivers/scsi/virtio_scsi.c @@ -74,7 +74,7 @@ struct virtio_scsi { /* Get some buffers ready for event vq */ struct virtio_scsi_event_node event_list[VIRTIO_SCSI_EVENT_LEN]; - struct virtio_scsi_target_state *tgt[]; + struct virtio_scsi_target_state *tgt; }; static struct kmem_cache *virtscsi_cmd_cache; @@ -574,19 +574,9 @@ static void virtscsi_init_vq(struct virtio_scsi_vq *virtscsi_vq, virtscsi_vq->vq = vq; } -static struct virtio_scsi_target_state *virtscsi_alloc_tgt( - struct virtio_device *vdev, int sg_elems) +static void virtscsi_init_tgt(struct virtio_scsi_target_state *tgt) { - struct virtio_scsi_target_state *tgt; - gfp_t gfp_mask = GFP_KERNEL; - - /* We need extra sg elements at head and tail. */ - tgt = kmalloc(sizeof(*tgt), gfp_mask); - if (!tgt) - return NULL; - spin_lock_init(&tgt->tgt_lock); - return tgt; } static void virtscsi_scan(struct virtio_device *vdev) @@ -600,16 +590,12 @@ static void virtscsi_remove_vqs(struct virtio_device *vdev) { struct Scsi_Host *sh = virtio_scsi_host(vdev); struct virtio_scsi *vscsi = shost_priv(sh); - u32 i, num_targets; /* Stop all the virtqueues. */ vdev->config->reset(vdev); - num_targets = sh->max_id; - for (i = 0; i < num_targets; i++) { - kfree(vscsi->tgt[i]); - vscsi->tgt[i] = NULL; - } + kfree(vscsi->tgt); + vscsi->tgt = NULL; vdev->config->del_vqs(vdev); } @@ -650,13 +636,14 @@ static int virtscsi_init(struct virtio_device *vdev, /* We need to know how many segments before we allocate. */ sg_elems = virtscsi_config_get(vdev, seg_max) ?: 1; - for (i = 0; i < num_targets; i++) { - vscsi->tgt[i] = virtscsi_alloc_tgt(vdev, sg_elems); - if (!vscsi->tgt[i]) { - err = -ENOMEM; - goto out; - } + vscsi->tgt = kmalloc(num_targets * sizeof(vscsi->tgt[0]), GFP_KERNEL); + if (!vscsi->tgt) { + err = -ENOMEM; + goto out; } + for (i = 0; i < num_targets; i++) + virtscsi_init_tgt(&vscsi->tgt[i]); + err = 0; out: @@ -675,9 +662,7 @@ static int virtscsi_probe(struct virtio_device *vdev) /* Allocate memory and link the structs together. */ num_targets = virtscsi_config_get(vdev, max_target) + 1; - shost = scsi_host_alloc(&virtscsi_host_template, - sizeof(*vscsi) - + num_targets * sizeof(struct virtio_scsi_target_state)); + shost = scsi_host_alloc(&virtscsi_host_template, sizeof(*vscsi)); if (!shost) return -ENOMEM;