Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 lifecycle fix in the auth code, a fix for a narrow race
condition on map, and a helpful message in the log when there is a
feature mismatch (which happens frequently now that the default
server-side options have changed)"

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/sage/ceph-client:
rbd: report unsupported features to syslog
rbd: fix rbd map vs notify races
libceph: make authorizer destruction independent of ceph_auth_client

+87 -92
+25 -27
drivers/block/rbd.c
··· 538 538 u8 *order, u64 *snap_size); 539 539 static int _rbd_dev_v2_snap_features(struct rbd_device *rbd_dev, u64 snap_id, 540 540 u64 *snap_features); 541 - static u64 rbd_snap_id_by_name(struct rbd_device *rbd_dev, const char *name); 542 541 543 542 static int rbd_open(struct block_device *bdev, fmode_t mode) 544 543 { ··· 3126 3127 struct rbd_device *rbd_dev = (struct rbd_device *)data; 3127 3128 int ret; 3128 3129 3129 - if (!rbd_dev) 3130 - return; 3131 - 3132 3130 dout("%s: \"%s\" notify_id %llu opcode %u\n", __func__, 3133 3131 rbd_dev->header_name, (unsigned long long)notify_id, 3134 3132 (unsigned int)opcode); ··· 3259 3263 3260 3264 ceph_osdc_cancel_event(rbd_dev->watch_event); 3261 3265 rbd_dev->watch_event = NULL; 3266 + 3267 + dout("%s flushing notifies\n", __func__); 3268 + ceph_osdc_flush_notifies(&rbd_dev->rbd_client->client->osdc); 3262 3269 } 3263 3270 3264 3271 /* ··· 3641 3642 static void rbd_dev_update_size(struct rbd_device *rbd_dev) 3642 3643 { 3643 3644 sector_t size; 3644 - bool removing; 3645 3645 3646 3646 /* 3647 - * Don't hold the lock while doing disk operations, 3648 - * or lock ordering will conflict with the bdev mutex via: 3649 - * rbd_add() -> blkdev_get() -> rbd_open() 3647 + * If EXISTS is not set, rbd_dev->disk may be NULL, so don't 3648 + * try to update its size. If REMOVING is set, updating size 3649 + * is just useless work since the device can't be opened. 3650 3650 */ 3651 - spin_lock_irq(&rbd_dev->lock); 3652 - removing = test_bit(RBD_DEV_FLAG_REMOVING, &rbd_dev->flags); 3653 - spin_unlock_irq(&rbd_dev->lock); 3654 - /* 3655 - * If the device is being removed, rbd_dev->disk has 3656 - * been destroyed, so don't try to update its size 3657 - */ 3658 - if (!removing) { 3651 + if (test_bit(RBD_DEV_FLAG_EXISTS, &rbd_dev->flags) && 3652 + !test_bit(RBD_DEV_FLAG_REMOVING, &rbd_dev->flags)) { 3659 3653 size = (sector_t)rbd_dev->mapping.size / SECTOR_SIZE; 3660 3654 dout("setting size to %llu sectors", (unsigned long long)size); 3661 3655 set_capacity(rbd_dev->disk, size); ··· 4183 4191 __le64 features; 4184 4192 __le64 incompat; 4185 4193 } __attribute__ ((packed)) features_buf = { 0 }; 4186 - u64 incompat; 4194 + u64 unsup; 4187 4195 int ret; 4188 4196 4189 4197 ret = rbd_obj_method_sync(rbd_dev, rbd_dev->header_name, ··· 4196 4204 if (ret < sizeof (features_buf)) 4197 4205 return -ERANGE; 4198 4206 4199 - incompat = le64_to_cpu(features_buf.incompat); 4200 - if (incompat & ~RBD_FEATURES_SUPPORTED) 4207 + unsup = le64_to_cpu(features_buf.incompat) & ~RBD_FEATURES_SUPPORTED; 4208 + if (unsup) { 4209 + rbd_warn(rbd_dev, "image uses unsupported features: 0x%llx", 4210 + unsup); 4201 4211 return -ENXIO; 4212 + } 4202 4213 4203 4214 *snap_features = le64_to_cpu(features_buf.features); 4204 4215 ··· 5182 5187 return ret; 5183 5188 } 5184 5189 5190 + /* 5191 + * rbd_dev->header_rwsem must be locked for write and will be unlocked 5192 + * upon return. 5193 + */ 5185 5194 static int rbd_dev_device_setup(struct rbd_device *rbd_dev) 5186 5195 { 5187 5196 int ret; ··· 5194 5195 5195 5196 ret = rbd_dev_id_get(rbd_dev); 5196 5197 if (ret) 5197 - return ret; 5198 + goto err_out_unlock; 5198 5199 5199 5200 BUILD_BUG_ON(DEV_NAME_LEN 5200 5201 < sizeof (RBD_DRV_NAME) + MAX_INT_FORMAT_WIDTH); ··· 5235 5236 /* Everything's ready. Announce the disk to the world. */ 5236 5237 5237 5238 set_bit(RBD_DEV_FLAG_EXISTS, &rbd_dev->flags); 5238 - add_disk(rbd_dev->disk); 5239 + up_write(&rbd_dev->header_rwsem); 5239 5240 5241 + add_disk(rbd_dev->disk); 5240 5242 pr_info("%s: added with size 0x%llx\n", rbd_dev->disk->disk_name, 5241 5243 (unsigned long long) rbd_dev->mapping.size); 5242 5244 ··· 5252 5252 unregister_blkdev(rbd_dev->major, rbd_dev->name); 5253 5253 err_out_id: 5254 5254 rbd_dev_id_put(rbd_dev); 5255 + err_out_unlock: 5256 + up_write(&rbd_dev->header_rwsem); 5255 5257 return ret; 5256 5258 } 5257 5259 ··· 5444 5442 spec = NULL; /* rbd_dev now owns this */ 5445 5443 rbd_opts = NULL; /* rbd_dev now owns this */ 5446 5444 5445 + down_write(&rbd_dev->header_rwsem); 5447 5446 rc = rbd_dev_image_probe(rbd_dev, 0); 5448 5447 if (rc < 0) 5449 5448 goto err_out_rbd_dev; ··· 5474 5471 return rc; 5475 5472 5476 5473 err_out_rbd_dev: 5474 + up_write(&rbd_dev->header_rwsem); 5477 5475 rbd_dev_destroy(rbd_dev); 5478 5476 err_out_client: 5479 5477 rbd_put_client(rbdc); ··· 5581 5577 return ret; 5582 5578 5583 5579 rbd_dev_header_unwatch_sync(rbd_dev); 5584 - /* 5585 - * flush remaining watch callbacks - these must be complete 5586 - * before the osd_client is shutdown 5587 - */ 5588 - dout("%s: flushing notifies", __func__); 5589 - ceph_osdc_flush_notifies(&rbd_dev->rbd_client->client->osdc); 5590 5580 5591 5581 /* 5592 5582 * Don't free anything from rbd_dev->disk until after all
+2 -4
fs/ceph/mds_client.c
··· 386 386 atomic_read(&s->s_ref), atomic_read(&s->s_ref)-1); 387 387 if (atomic_dec_and_test(&s->s_ref)) { 388 388 if (s->s_auth.authorizer) 389 - ceph_auth_destroy_authorizer( 390 - s->s_mdsc->fsc->client->monc.auth, 391 - s->s_auth.authorizer); 389 + ceph_auth_destroy_authorizer(s->s_auth.authorizer); 392 390 kfree(s); 393 391 } 394 392 } ··· 3898 3900 struct ceph_auth_handshake *auth = &s->s_auth; 3899 3901 3900 3902 if (force_new && auth->authorizer) { 3901 - ceph_auth_destroy_authorizer(ac, auth->authorizer); 3903 + ceph_auth_destroy_authorizer(auth->authorizer); 3902 3904 auth->authorizer = NULL; 3903 3905 } 3904 3906 if (!auth->authorizer) {
+5 -5
include/linux/ceph/auth.h
··· 12 12 */ 13 13 14 14 struct ceph_auth_client; 15 - struct ceph_authorizer; 16 15 struct ceph_msg; 16 + 17 + struct ceph_authorizer { 18 + void (*destroy)(struct ceph_authorizer *); 19 + }; 17 20 18 21 struct ceph_auth_handshake { 19 22 struct ceph_authorizer *authorizer; ··· 65 62 struct ceph_auth_handshake *auth); 66 63 int (*verify_authorizer_reply)(struct ceph_auth_client *ac, 67 64 struct ceph_authorizer *a, size_t len); 68 - void (*destroy_authorizer)(struct ceph_auth_client *ac, 69 - struct ceph_authorizer *a); 70 65 void (*invalidate_authorizer)(struct ceph_auth_client *ac, 71 66 int peer_type); 72 67 ··· 113 112 extern int ceph_auth_create_authorizer(struct ceph_auth_client *ac, 114 113 int peer_type, 115 114 struct ceph_auth_handshake *auth); 116 - extern void ceph_auth_destroy_authorizer(struct ceph_auth_client *ac, 117 - struct ceph_authorizer *a); 115 + void ceph_auth_destroy_authorizer(struct ceph_authorizer *a); 118 116 extern int ceph_auth_update_authorizer(struct ceph_auth_client *ac, 119 117 int peer_type, 120 118 struct ceph_auth_handshake *a);
-1
include/linux/ceph/osd_client.h
··· 16 16 struct ceph_snap_context; 17 17 struct ceph_osd_request; 18 18 struct ceph_osd_client; 19 - struct ceph_authorizer; 20 19 21 20 /* 22 21 * completion callback for async writepages
+2 -6
net/ceph/auth.c
··· 293 293 } 294 294 EXPORT_SYMBOL(ceph_auth_create_authorizer); 295 295 296 - void ceph_auth_destroy_authorizer(struct ceph_auth_client *ac, 297 - struct ceph_authorizer *a) 296 + void ceph_auth_destroy_authorizer(struct ceph_authorizer *a) 298 297 { 299 - mutex_lock(&ac->mutex); 300 - if (ac->ops && ac->ops->destroy_authorizer) 301 - ac->ops->destroy_authorizer(ac, a); 302 - mutex_unlock(&ac->mutex); 298 + a->destroy(a); 303 299 } 304 300 EXPORT_SYMBOL(ceph_auth_destroy_authorizer); 305 301
+39 -32
net/ceph/auth_none.c
··· 16 16 struct ceph_auth_none_info *xi = ac->private; 17 17 18 18 xi->starting = true; 19 - xi->built_authorizer = false; 20 19 } 21 20 22 21 static void destroy(struct ceph_auth_client *ac) ··· 38 39 return xi->starting; 39 40 } 40 41 42 + static int ceph_auth_none_build_authorizer(struct ceph_auth_client *ac, 43 + struct ceph_none_authorizer *au) 44 + { 45 + void *p = au->buf; 46 + void *const end = p + sizeof(au->buf); 47 + int ret; 48 + 49 + ceph_encode_8_safe(&p, end, 1, e_range); 50 + ret = ceph_entity_name_encode(ac->name, &p, end); 51 + if (ret < 0) 52 + return ret; 53 + 54 + ceph_encode_64_safe(&p, end, ac->global_id, e_range); 55 + au->buf_len = p - (void *)au->buf; 56 + dout("%s built authorizer len %d\n", __func__, au->buf_len); 57 + return 0; 58 + 59 + e_range: 60 + return -ERANGE; 61 + } 62 + 41 63 static int build_request(struct ceph_auth_client *ac, void *buf, void *end) 42 64 { 43 65 return 0; ··· 77 57 return result; 78 58 } 79 59 60 + static void ceph_auth_none_destroy_authorizer(struct ceph_authorizer *a) 61 + { 62 + kfree(a); 63 + } 64 + 80 65 /* 81 - * build an 'authorizer' with our entity_name and global_id. we can 82 - * reuse a single static copy since it is identical for all services 83 - * we connect to. 66 + * build an 'authorizer' with our entity_name and global_id. it is 67 + * identical for all services we connect to. 84 68 */ 85 69 static int ceph_auth_none_create_authorizer( 86 70 struct ceph_auth_client *ac, int peer_type, 87 71 struct ceph_auth_handshake *auth) 88 72 { 89 - struct ceph_auth_none_info *ai = ac->private; 90 - struct ceph_none_authorizer *au = &ai->au; 91 - void *p, *end; 73 + struct ceph_none_authorizer *au; 92 74 int ret; 93 75 94 - if (!ai->built_authorizer) { 95 - p = au->buf; 96 - end = p + sizeof(au->buf); 97 - ceph_encode_8(&p, 1); 98 - ret = ceph_entity_name_encode(ac->name, &p, end - 8); 99 - if (ret < 0) 100 - goto bad; 101 - ceph_decode_need(&p, end, sizeof(u64), bad2); 102 - ceph_encode_64(&p, ac->global_id); 103 - au->buf_len = p - (void *)au->buf; 104 - ai->built_authorizer = true; 105 - dout("built authorizer len %d\n", au->buf_len); 76 + au = kmalloc(sizeof(*au), GFP_NOFS); 77 + if (!au) 78 + return -ENOMEM; 79 + 80 + au->base.destroy = ceph_auth_none_destroy_authorizer; 81 + 82 + ret = ceph_auth_none_build_authorizer(ac, au); 83 + if (ret) { 84 + kfree(au); 85 + return ret; 106 86 } 107 87 108 88 auth->authorizer = (struct ceph_authorizer *) au; ··· 112 92 auth->authorizer_reply_buf_len = sizeof (au->reply_buf); 113 93 114 94 return 0; 115 - 116 - bad2: 117 - ret = -ERANGE; 118 - bad: 119 - return ret; 120 - } 121 - 122 - static void ceph_auth_none_destroy_authorizer(struct ceph_auth_client *ac, 123 - struct ceph_authorizer *a) 124 - { 125 - /* nothing to do */ 126 95 } 127 96 128 97 static const struct ceph_auth_client_ops ceph_auth_none_ops = { ··· 123 114 .build_request = build_request, 124 115 .handle_reply = handle_reply, 125 116 .create_authorizer = ceph_auth_none_create_authorizer, 126 - .destroy_authorizer = ceph_auth_none_destroy_authorizer, 127 117 }; 128 118 129 119 int ceph_auth_none_init(struct ceph_auth_client *ac) ··· 135 127 return -ENOMEM; 136 128 137 129 xi->starting = true; 138 - xi->built_authorizer = false; 139 130 140 131 ac->protocol = CEPH_AUTH_NONE; 141 132 ac->private = xi;
+1 -2
net/ceph/auth_none.h
··· 12 12 */ 13 13 14 14 struct ceph_none_authorizer { 15 + struct ceph_authorizer base; 15 16 char buf[128]; 16 17 int buf_len; 17 18 char reply_buf[0]; ··· 20 19 21 20 struct ceph_auth_none_info { 22 21 bool starting; 23 - bool built_authorizer; 24 - struct ceph_none_authorizer au; /* we only need one; it's static */ 25 22 }; 26 23 27 24 int ceph_auth_none_init(struct ceph_auth_client *ac);
+10 -11
net/ceph/auth_x.c
··· 565 565 return -EAGAIN; 566 566 } 567 567 568 + static void ceph_x_destroy_authorizer(struct ceph_authorizer *a) 569 + { 570 + struct ceph_x_authorizer *au = (void *)a; 571 + 572 + ceph_x_authorizer_cleanup(au); 573 + kfree(au); 574 + } 575 + 568 576 static int ceph_x_create_authorizer( 569 577 struct ceph_auth_client *ac, int peer_type, 570 578 struct ceph_auth_handshake *auth) ··· 588 580 au = kzalloc(sizeof(*au), GFP_NOFS); 589 581 if (!au) 590 582 return -ENOMEM; 583 + 584 + au->base.destroy = ceph_x_destroy_authorizer; 591 585 592 586 ret = ceph_x_build_authorizer(ac, th, au); 593 587 if (ret) { ··· 652 642 au->nonce, le64_to_cpu(reply.nonce_plus_one), ret); 653 643 return ret; 654 644 } 655 - 656 - static void ceph_x_destroy_authorizer(struct ceph_auth_client *ac, 657 - struct ceph_authorizer *a) 658 - { 659 - struct ceph_x_authorizer *au = (void *)a; 660 - 661 - ceph_x_authorizer_cleanup(au); 662 - kfree(au); 663 - } 664 - 665 645 666 646 static void ceph_x_reset(struct ceph_auth_client *ac) 667 647 { ··· 770 770 .create_authorizer = ceph_x_create_authorizer, 771 771 .update_authorizer = ceph_x_update_authorizer, 772 772 .verify_authorizer_reply = ceph_x_verify_authorizer_reply, 773 - .destroy_authorizer = ceph_x_destroy_authorizer, 774 773 .invalidate_authorizer = ceph_x_invalidate_authorizer, 775 774 .reset = ceph_x_reset, 776 775 .destroy = ceph_x_destroy,
+1
net/ceph/auth_x.h
··· 26 26 27 27 28 28 struct ceph_x_authorizer { 29 + struct ceph_authorizer base; 29 30 struct ceph_crypto_key session_key; 30 31 struct ceph_buffer *buf; 31 32 unsigned int service;
+2 -4
net/ceph/osd_client.c
··· 1087 1087 dout("put_osd %p %d -> %d\n", osd, atomic_read(&osd->o_ref), 1088 1088 atomic_read(&osd->o_ref) - 1); 1089 1089 if (atomic_dec_and_test(&osd->o_ref)) { 1090 - struct ceph_auth_client *ac = osd->o_osdc->client->monc.auth; 1091 - 1092 1090 if (osd->o_auth.authorizer) 1093 - ceph_auth_destroy_authorizer(ac, osd->o_auth.authorizer); 1091 + ceph_auth_destroy_authorizer(osd->o_auth.authorizer); 1094 1092 kfree(osd); 1095 1093 } 1096 1094 } ··· 2982 2984 struct ceph_auth_handshake *auth = &o->o_auth; 2983 2985 2984 2986 if (force_new && auth->authorizer) { 2985 - ceph_auth_destroy_authorizer(ac, auth->authorizer); 2987 + ceph_auth_destroy_authorizer(auth->authorizer); 2986 2988 auth->authorizer = NULL; 2987 2989 } 2988 2990 if (!auth->authorizer) {