return;
}
-static int xen_blkif_alloc_rings(struct xen_blkif *blkif)
+static int xen_blkif_alloc_rings(struct xen_blkif *blkif,
+ unsigned int nr_rings)
{
unsigned int r;
+ struct xen_blkif_ring *rings;
- blkif->rings = kcalloc(blkif->nr_rings, sizeof(struct xen_blkif_ring),
- GFP_KERNEL);
- if (!blkif->rings)
+ rings = kcalloc(nr_rings, sizeof(struct xen_blkif_ring), GFP_KERNEL);
+ if (!rings)
return -ENOMEM;
+ write_lock(&blkif->rings_lock);
+
+ blkif->rings = rings;
+ blkif->nr_rings = nr_rings;
+
+ write_unlock(&blkif->rings_lock);
+
for (r = 0; r < blkif->nr_rings; r++) {
struct xen_blkif_ring *ring = &blkif->rings[r];
blkif->domid = domid;
atomic_set(&blkif->refcnt, 1);
init_completion(&blkif->drain_complete);
+ rwlock_init(&blkif->rings_lock);
/*
* Because freeing back to the cache may be deferred, it is not
struct pending_req *req, *n;
unsigned int j, r;
bool busy = false;
+ struct xen_blkif_ring *rings;
for (r = 0; r < blkif->nr_rings; r++) {
struct xen_blkif_ring *ring = &blkif->rings[r];
* blkif->rings was allocated in connect_ring, so we should free it in
* here.
*/
- kfree(blkif->rings);
+ write_lock(&blkif->rings_lock);
+
+ rings = blkif->rings;
blkif->rings = NULL;
blkif->nr_rings = 0;
+ write_unlock(&blkif->rings_lock);
+
+ kfree(rings);
+
return 0;
}
unsigned int i; \
unsigned long long result = 0; \
\
+ read_lock(&blkif->rings_lock); \
if (!blkif->rings) \
goto out; \
\
} \
\
out: \
+ read_unlock(&blkif->rings_lock); \
return sprintf(buf, format, result); \
} \
static DEVICE_ATTR(name, 0444, show_##name, NULL)
requested_num_queues, xenblk_max_queues);
return -ENOSYS;
}
- blkif->nr_rings = requested_num_queues;
- if (xen_blkif_alloc_rings(blkif))
+ if (xen_blkif_alloc_rings(blkif, requested_num_queues))
return -ENOMEM;
pr_info("%s: using %d queues, protocol %d (%s) %s\n", dev->nodename,