Skip to content

Commit ce1928d

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/sage/ceph-client
Pull ceph fixes from Sage Weil: "There is a GFP flag fix from Mike Christie, an error code fix from Jan, and fixes for two unnecessary allocations (kmalloc and workqueue) from Ilya. All are well tested. Ilya has one other fix on the way but it didn't get tested in time" * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/sage/ceph-client: libceph: eliminate unnecessary allocation in process_one_ticket() rbd: Fix error recovery in rbd_obj_read_sync() libceph: use memalloc flags for net IO rbd: use a single workqueue for all devices
2 parents f4ca536 + e9226d7 commit ce1928d

File tree

3 files changed

+38
-32
lines changed

3 files changed

+38
-32
lines changed

drivers/block/rbd.c

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,6 @@ struct rbd_device {
342342

343343
struct list_head rq_queue; /* incoming rq queue */
344344
spinlock_t lock; /* queue, flags, open_count */
345-
struct workqueue_struct *rq_wq;
346345
struct work_struct rq_work;
347346

348347
struct rbd_image_header header;
@@ -402,6 +401,8 @@ static struct kmem_cache *rbd_segment_name_cache;
402401
static int rbd_major;
403402
static DEFINE_IDA(rbd_dev_id_ida);
404403

404+
static struct workqueue_struct *rbd_wq;
405+
405406
/*
406407
* Default to false for now, as single-major requires >= 0.75 version of
407408
* userspace rbd utility.
@@ -3452,7 +3453,7 @@ static void rbd_request_fn(struct request_queue *q)
34523453
}
34533454

34543455
if (queued)
3455-
queue_work(rbd_dev->rq_wq, &rbd_dev->rq_work);
3456+
queue_work(rbd_wq, &rbd_dev->rq_work);
34563457
}
34573458

34583459
/*
@@ -3532,7 +3533,7 @@ static int rbd_obj_read_sync(struct rbd_device *rbd_dev,
35323533
page_count = (u32) calc_pages_for(offset, length);
35333534
pages = ceph_alloc_page_vector(page_count, GFP_KERNEL);
35343535
if (IS_ERR(pages))
3535-
ret = PTR_ERR(pages);
3536+
return PTR_ERR(pages);
35363537

35373538
ret = -ENOMEM;
35383539
obj_request = rbd_obj_request_create(object_name, offset, length,
@@ -5242,16 +5243,9 @@ static int rbd_dev_device_setup(struct rbd_device *rbd_dev)
52425243
set_capacity(rbd_dev->disk, rbd_dev->mapping.size / SECTOR_SIZE);
52435244
set_disk_ro(rbd_dev->disk, rbd_dev->mapping.read_only);
52445245

5245-
rbd_dev->rq_wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 0,
5246-
rbd_dev->disk->disk_name);
5247-
if (!rbd_dev->rq_wq) {
5248-
ret = -ENOMEM;
5249-
goto err_out_mapping;
5250-
}
5251-
52525246
ret = rbd_bus_add_dev(rbd_dev);
52535247
if (ret)
5254-
goto err_out_workqueue;
5248+
goto err_out_mapping;
52555249

52565250
/* Everything's ready. Announce the disk to the world. */
52575251

@@ -5263,9 +5257,6 @@ static int rbd_dev_device_setup(struct rbd_device *rbd_dev)
52635257

52645258
return ret;
52655259

5266-
err_out_workqueue:
5267-
destroy_workqueue(rbd_dev->rq_wq);
5268-
rbd_dev->rq_wq = NULL;
52695260
err_out_mapping:
52705261
rbd_dev_mapping_clear(rbd_dev);
52715262
err_out_disk:
@@ -5512,7 +5503,6 @@ static void rbd_dev_device_release(struct device *dev)
55125503
{
55135504
struct rbd_device *rbd_dev = dev_to_rbd_dev(dev);
55145505

5515-
destroy_workqueue(rbd_dev->rq_wq);
55165506
rbd_free_disk(rbd_dev);
55175507
clear_bit(RBD_DEV_FLAG_EXISTS, &rbd_dev->flags);
55185508
rbd_dev_mapping_clear(rbd_dev);
@@ -5716,11 +5706,21 @@ static int __init rbd_init(void)
57165706
if (rc)
57175707
return rc;
57185708

5709+
/*
5710+
* The number of active work items is limited by the number of
5711+
* rbd devices, so leave @max_active at default.
5712+
*/
5713+
rbd_wq = alloc_workqueue(RBD_DRV_NAME, WQ_MEM_RECLAIM, 0);
5714+
if (!rbd_wq) {
5715+
rc = -ENOMEM;
5716+
goto err_out_slab;
5717+
}
5718+
57195719
if (single_major) {
57205720
rbd_major = register_blkdev(0, RBD_DRV_NAME);
57215721
if (rbd_major < 0) {
57225722
rc = rbd_major;
5723-
goto err_out_slab;
5723+
goto err_out_wq;
57245724
}
57255725
}
57265726

@@ -5738,6 +5738,8 @@ static int __init rbd_init(void)
57385738
err_out_blkdev:
57395739
if (single_major)
57405740
unregister_blkdev(rbd_major, RBD_DRV_NAME);
5741+
err_out_wq:
5742+
destroy_workqueue(rbd_wq);
57415743
err_out_slab:
57425744
rbd_slab_exit();
57435745
return rc;
@@ -5749,6 +5751,7 @@ static void __exit rbd_exit(void)
57495751
rbd_sysfs_cleanup();
57505752
if (single_major)
57515753
unregister_blkdev(rbd_major, RBD_DRV_NAME);
5754+
destroy_workqueue(rbd_wq);
57525755
rbd_slab_exit();
57535756
}
57545757

net/ceph/auth_x.c

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ static int process_one_ticket(struct ceph_auth_client *ac,
149149
struct ceph_crypto_key old_key;
150150
void *ticket_buf = NULL;
151151
void *tp, *tpend;
152+
void **ptp;
152153
struct ceph_timespec new_validity;
153154
struct ceph_crypto_key new_session_key;
154155
struct ceph_buffer *new_ticket_blob;
@@ -208,25 +209,19 @@ static int process_one_ticket(struct ceph_auth_client *ac,
208209
goto out;
209210
}
210211
tp = ticket_buf;
211-
dlen = ceph_decode_32(&tp);
212+
ptp = &tp;
213+
tpend = *ptp + dlen;
212214
} else {
213215
/* unencrypted */
214-
ceph_decode_32_safe(p, end, dlen, bad);
215-
ticket_buf = kmalloc(dlen, GFP_NOFS);
216-
if (!ticket_buf) {
217-
ret = -ENOMEM;
218-
goto out;
219-
}
220-
tp = ticket_buf;
221-
ceph_decode_need(p, end, dlen, bad);
222-
ceph_decode_copy(p, ticket_buf, dlen);
216+
ptp = p;
217+
tpend = end;
223218
}
224-
tpend = tp + dlen;
219+
ceph_decode_32_safe(ptp, tpend, dlen, bad);
225220
dout(" ticket blob is %d bytes\n", dlen);
226-
ceph_decode_need(&tp, tpend, 1 + sizeof(u64), bad);
227-
blob_struct_v = ceph_decode_8(&tp);
228-
new_secret_id = ceph_decode_64(&tp);
229-
ret = ceph_decode_buffer(&new_ticket_blob, &tp, tpend);
221+
ceph_decode_need(ptp, tpend, 1 + sizeof(u64), bad);
222+
blob_struct_v = ceph_decode_8(ptp);
223+
new_secret_id = ceph_decode_64(ptp);
224+
ret = ceph_decode_buffer(&new_ticket_blob, ptp, tpend);
230225
if (ret)
231226
goto out;
232227

net/ceph/messenger.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ static int ceph_tcp_connect(struct ceph_connection *con)
484484
IPPROTO_TCP, &sock);
485485
if (ret)
486486
return ret;
487-
sock->sk->sk_allocation = GFP_NOFS;
487+
sock->sk->sk_allocation = GFP_NOFS | __GFP_MEMALLOC;
488488

489489
#ifdef CONFIG_LOCKDEP
490490
lockdep_set_class(&sock->sk->sk_lock, &socket_class);
@@ -509,6 +509,9 @@ static int ceph_tcp_connect(struct ceph_connection *con)
509509

510510
return ret;
511511
}
512+
513+
sk_set_memalloc(sock->sk);
514+
512515
con->sock = sock;
513516
return 0;
514517
}
@@ -2769,8 +2772,11 @@ static void con_work(struct work_struct *work)
27692772
{
27702773
struct ceph_connection *con = container_of(work, struct ceph_connection,
27712774
work.work);
2775+
unsigned long pflags = current->flags;
27722776
bool fault;
27732777

2778+
current->flags |= PF_MEMALLOC;
2779+
27742780
mutex_lock(&con->mutex);
27752781
while (true) {
27762782
int ret;
@@ -2824,6 +2830,8 @@ static void con_work(struct work_struct *work)
28242830
con_fault_finish(con);
28252831

28262832
con->ops->put(con);
2833+
2834+
tsk_restore_flags(current, pflags, PF_MEMALLOC);
28272835
}
28282836

28292837
/*

0 commit comments

Comments
 (0)