diff options
author | Yehuda Sadeh <yehuda@hq.newdream.net> | 2010-04-22 18:40:37 -0400 |
---|---|---|
committer | Sage Weil <sage@newdream.net> | 2010-05-17 18:25:33 -0400 |
commit | f8c76f6f250edbdc9d2011b0e05d196a3d8ae895 (patch) | |
tree | b53964559534aa989b3e24a404104631d67be8b6 /fs/ceph/mon_client.c | |
parent | dbad185d4939ffb806f6fa753ef9f470e3b72b62 (diff) |
ceph: make mon client statfs handling more generic
This is being done so that we could reuse the statfs
infrastructure with other requests that return values.
Signed-off-by: Yehuda Sadeh <yehuda@hq.newdream.net>
Signed-off-by: Sage Weil <sage@newdream.net>
Diffstat (limited to 'fs/ceph/mon_client.c')
-rw-r--r-- | fs/ceph/mon_client.c | 82 |
1 files changed, 41 insertions, 41 deletions
diff --git a/fs/ceph/mon_client.c b/fs/ceph/mon_client.c index 9900706fee75..7df2f8c157f1 100644 --- a/fs/ceph/mon_client.c +++ b/fs/ceph/mon_client.c | |||
@@ -353,14 +353,14 @@ out: | |||
353 | /* | 353 | /* |
354 | * statfs | 354 | * statfs |
355 | */ | 355 | */ |
356 | static struct ceph_mon_statfs_request *__lookup_statfs( | 356 | static struct ceph_mon_generic_request *__lookup_generic_req( |
357 | struct ceph_mon_client *monc, u64 tid) | 357 | struct ceph_mon_client *monc, u64 tid) |
358 | { | 358 | { |
359 | struct ceph_mon_statfs_request *req; | 359 | struct ceph_mon_generic_request *req; |
360 | struct rb_node *n = monc->statfs_request_tree.rb_node; | 360 | struct rb_node *n = monc->generic_request_tree.rb_node; |
361 | 361 | ||
362 | while (n) { | 362 | while (n) { |
363 | req = rb_entry(n, struct ceph_mon_statfs_request, node); | 363 | req = rb_entry(n, struct ceph_mon_generic_request, node); |
364 | if (tid < req->tid) | 364 | if (tid < req->tid) |
365 | n = n->rb_left; | 365 | n = n->rb_left; |
366 | else if (tid > req->tid) | 366 | else if (tid > req->tid) |
@@ -371,16 +371,16 @@ static struct ceph_mon_statfs_request *__lookup_statfs( | |||
371 | return NULL; | 371 | return NULL; |
372 | } | 372 | } |
373 | 373 | ||
374 | static void __insert_statfs(struct ceph_mon_client *monc, | 374 | static void __insert_generic_request(struct ceph_mon_client *monc, |
375 | struct ceph_mon_statfs_request *new) | 375 | struct ceph_mon_generic_request *new) |
376 | { | 376 | { |
377 | struct rb_node **p = &monc->statfs_request_tree.rb_node; | 377 | struct rb_node **p = &monc->generic_request_tree.rb_node; |
378 | struct rb_node *parent = NULL; | 378 | struct rb_node *parent = NULL; |
379 | struct ceph_mon_statfs_request *req = NULL; | 379 | struct ceph_mon_generic_request *req = NULL; |
380 | 380 | ||
381 | while (*p) { | 381 | while (*p) { |
382 | parent = *p; | 382 | parent = *p; |
383 | req = rb_entry(parent, struct ceph_mon_statfs_request, node); | 383 | req = rb_entry(parent, struct ceph_mon_generic_request, node); |
384 | if (new->tid < req->tid) | 384 | if (new->tid < req->tid) |
385 | p = &(*p)->rb_left; | 385 | p = &(*p)->rb_left; |
386 | else if (new->tid > req->tid) | 386 | else if (new->tid > req->tid) |
@@ -390,13 +390,13 @@ static void __insert_statfs(struct ceph_mon_client *monc, | |||
390 | } | 390 | } |
391 | 391 | ||
392 | rb_link_node(&new->node, parent, p); | 392 | rb_link_node(&new->node, parent, p); |
393 | rb_insert_color(&new->node, &monc->statfs_request_tree); | 393 | rb_insert_color(&new->node, &monc->generic_request_tree); |
394 | } | 394 | } |
395 | 395 | ||
396 | static void release_statfs_request(struct kref *kref) | 396 | static void release_generic_request(struct kref *kref) |
397 | { | 397 | { |
398 | struct ceph_mon_statfs_request *req = | 398 | struct ceph_mon_generic_request *req = |
399 | container_of(kref, struct ceph_mon_statfs_request, kref); | 399 | container_of(kref, struct ceph_mon_generic_request, kref); |
400 | 400 | ||
401 | if (req->reply) | 401 | if (req->reply) |
402 | ceph_msg_put(req->reply); | 402 | ceph_msg_put(req->reply); |
@@ -404,33 +404,33 @@ static void release_statfs_request(struct kref *kref) | |||
404 | ceph_msg_put(req->request); | 404 | ceph_msg_put(req->request); |
405 | } | 405 | } |
406 | 406 | ||
407 | static void put_statfs_request(struct ceph_mon_statfs_request *req) | 407 | static void put_generic_request(struct ceph_mon_generic_request *req) |
408 | { | 408 | { |
409 | kref_put(&req->kref, release_statfs_request); | 409 | kref_put(&req->kref, release_generic_request); |
410 | } | 410 | } |
411 | 411 | ||
412 | static void get_statfs_request(struct ceph_mon_statfs_request *req) | 412 | static void get_generic_request(struct ceph_mon_generic_request *req) |
413 | { | 413 | { |
414 | kref_get(&req->kref); | 414 | kref_get(&req->kref); |
415 | } | 415 | } |
416 | 416 | ||
417 | static struct ceph_msg *get_statfs_reply(struct ceph_connection *con, | 417 | static struct ceph_msg *get_generic_reply(struct ceph_connection *con, |
418 | struct ceph_msg_header *hdr, | 418 | struct ceph_msg_header *hdr, |
419 | int *skip) | 419 | int *skip) |
420 | { | 420 | { |
421 | struct ceph_mon_client *monc = con->private; | 421 | struct ceph_mon_client *monc = con->private; |
422 | struct ceph_mon_statfs_request *req; | 422 | struct ceph_mon_generic_request *req; |
423 | u64 tid = le64_to_cpu(hdr->tid); | 423 | u64 tid = le64_to_cpu(hdr->tid); |
424 | struct ceph_msg *m; | 424 | struct ceph_msg *m; |
425 | 425 | ||
426 | mutex_lock(&monc->mutex); | 426 | mutex_lock(&monc->mutex); |
427 | req = __lookup_statfs(monc, tid); | 427 | req = __lookup_generic_req(monc, tid); |
428 | if (!req) { | 428 | if (!req) { |
429 | dout("get_statfs_reply %lld dne\n", tid); | 429 | dout("get_generic_reply %lld dne\n", tid); |
430 | *skip = 1; | 430 | *skip = 1; |
431 | m = NULL; | 431 | m = NULL; |
432 | } else { | 432 | } else { |
433 | dout("get_statfs_reply %lld got %p\n", tid, req->reply); | 433 | dout("get_generic_reply %lld got %p\n", tid, req->reply); |
434 | m = ceph_msg_get(req->reply); | 434 | m = ceph_msg_get(req->reply); |
435 | /* | 435 | /* |
436 | * we don't need to track the connection reading into | 436 | * we don't need to track the connection reading into |
@@ -445,7 +445,7 @@ static struct ceph_msg *get_statfs_reply(struct ceph_connection *con, | |||
445 | static void handle_statfs_reply(struct ceph_mon_client *monc, | 445 | static void handle_statfs_reply(struct ceph_mon_client *monc, |
446 | struct ceph_msg *msg) | 446 | struct ceph_msg *msg) |
447 | { | 447 | { |
448 | struct ceph_mon_statfs_request *req; | 448 | struct ceph_mon_generic_request *req; |
449 | struct ceph_mon_statfs_reply *reply = msg->front.iov_base; | 449 | struct ceph_mon_statfs_reply *reply = msg->front.iov_base; |
450 | u64 tid = le64_to_cpu(msg->hdr.tid); | 450 | u64 tid = le64_to_cpu(msg->hdr.tid); |
451 | 451 | ||
@@ -454,21 +454,21 @@ static void handle_statfs_reply(struct ceph_mon_client *monc, | |||
454 | dout("handle_statfs_reply %p tid %llu\n", msg, tid); | 454 | dout("handle_statfs_reply %p tid %llu\n", msg, tid); |
455 | 455 | ||
456 | mutex_lock(&monc->mutex); | 456 | mutex_lock(&monc->mutex); |
457 | req = __lookup_statfs(monc, tid); | 457 | req = __lookup_generic_req(monc, tid); |
458 | if (req) { | 458 | if (req) { |
459 | *req->buf = reply->st; | 459 | *(struct ceph_statfs *)req->buf = reply->st; |
460 | req->result = 0; | 460 | req->result = 0; |
461 | get_statfs_request(req); | 461 | get_generic_request(req); |
462 | } | 462 | } |
463 | mutex_unlock(&monc->mutex); | 463 | mutex_unlock(&monc->mutex); |
464 | if (req) { | 464 | if (req) { |
465 | complete(&req->completion); | 465 | complete(&req->completion); |
466 | put_statfs_request(req); | 466 | put_generic_request(req); |
467 | } | 467 | } |
468 | return; | 468 | return; |
469 | 469 | ||
470 | bad: | 470 | bad: |
471 | pr_err("corrupt statfs reply, no tid\n"); | 471 | pr_err("corrupt generic reply, no tid\n"); |
472 | ceph_msg_dump(msg); | 472 | ceph_msg_dump(msg); |
473 | } | 473 | } |
474 | 474 | ||
@@ -477,7 +477,7 @@ bad: | |||
477 | */ | 477 | */ |
478 | int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf) | 478 | int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf) |
479 | { | 479 | { |
480 | struct ceph_mon_statfs_request *req; | 480 | struct ceph_mon_generic_request *req; |
481 | struct ceph_mon_statfs *h; | 481 | struct ceph_mon_statfs *h; |
482 | int err; | 482 | int err; |
483 | 483 | ||
@@ -509,8 +509,8 @@ int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf) | |||
509 | mutex_lock(&monc->mutex); | 509 | mutex_lock(&monc->mutex); |
510 | req->tid = ++monc->last_tid; | 510 | req->tid = ++monc->last_tid; |
511 | req->request->hdr.tid = cpu_to_le64(req->tid); | 511 | req->request->hdr.tid = cpu_to_le64(req->tid); |
512 | __insert_statfs(monc, req); | 512 | __insert_generic_request(monc, req); |
513 | monc->num_statfs_requests++; | 513 | monc->num_generic_requests++; |
514 | mutex_unlock(&monc->mutex); | 514 | mutex_unlock(&monc->mutex); |
515 | 515 | ||
516 | /* send request and wait */ | 516 | /* send request and wait */ |
@@ -518,28 +518,28 @@ int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf) | |||
518 | err = wait_for_completion_interruptible(&req->completion); | 518 | err = wait_for_completion_interruptible(&req->completion); |
519 | 519 | ||
520 | mutex_lock(&monc->mutex); | 520 | mutex_lock(&monc->mutex); |
521 | rb_erase(&req->node, &monc->statfs_request_tree); | 521 | rb_erase(&req->node, &monc->generic_request_tree); |
522 | monc->num_statfs_requests--; | 522 | monc->num_generic_requests--; |
523 | mutex_unlock(&monc->mutex); | 523 | mutex_unlock(&monc->mutex); |
524 | 524 | ||
525 | if (!err) | 525 | if (!err) |
526 | err = req->result; | 526 | err = req->result; |
527 | 527 | ||
528 | out: | 528 | out: |
529 | kref_put(&req->kref, release_statfs_request); | 529 | kref_put(&req->kref, release_generic_request); |
530 | return err; | 530 | return err; |
531 | } | 531 | } |
532 | 532 | ||
533 | /* | 533 | /* |
534 | * Resend pending statfs requests. | 534 | * Resend pending statfs requests. |
535 | */ | 535 | */ |
536 | static void __resend_statfs(struct ceph_mon_client *monc) | 536 | static void __resend_generic_request(struct ceph_mon_client *monc) |
537 | { | 537 | { |
538 | struct ceph_mon_statfs_request *req; | 538 | struct ceph_mon_generic_request *req; |
539 | struct rb_node *p; | 539 | struct rb_node *p; |
540 | 540 | ||
541 | for (p = rb_first(&monc->statfs_request_tree); p; p = rb_next(p)) { | 541 | for (p = rb_first(&monc->generic_request_tree); p; p = rb_next(p)) { |
542 | req = rb_entry(p, struct ceph_mon_statfs_request, node); | 542 | req = rb_entry(p, struct ceph_mon_generic_request, node); |
543 | ceph_con_send(monc->con, ceph_msg_get(req->request)); | 543 | ceph_con_send(monc->con, ceph_msg_get(req->request)); |
544 | } | 544 | } |
545 | } | 545 | } |
@@ -652,8 +652,8 @@ int ceph_monc_init(struct ceph_mon_client *monc, struct ceph_client *cl) | |||
652 | monc->sub_sent = 0; | 652 | monc->sub_sent = 0; |
653 | 653 | ||
654 | INIT_DELAYED_WORK(&monc->delayed_work, delayed_work); | 654 | INIT_DELAYED_WORK(&monc->delayed_work, delayed_work); |
655 | monc->statfs_request_tree = RB_ROOT; | 655 | monc->generic_request_tree = RB_ROOT; |
656 | monc->num_statfs_requests = 0; | 656 | monc->num_generic_requests = 0; |
657 | monc->last_tid = 0; | 657 | monc->last_tid = 0; |
658 | 658 | ||
659 | monc->have_mdsmap = 0; | 659 | monc->have_mdsmap = 0; |
@@ -717,7 +717,7 @@ static void handle_auth_reply(struct ceph_mon_client *monc, | |||
717 | monc->client->msgr->inst.name.num = monc->auth->global_id; | 717 | monc->client->msgr->inst.name.num = monc->auth->global_id; |
718 | 718 | ||
719 | __send_subscribe(monc); | 719 | __send_subscribe(monc); |
720 | __resend_statfs(monc); | 720 | __resend_generic_request(monc); |
721 | } | 721 | } |
722 | mutex_unlock(&monc->mutex); | 722 | mutex_unlock(&monc->mutex); |
723 | } | 723 | } |
@@ -809,7 +809,7 @@ static struct ceph_msg *mon_alloc_msg(struct ceph_connection *con, | |||
809 | m = ceph_msg_get(monc->m_subscribe_ack); | 809 | m = ceph_msg_get(monc->m_subscribe_ack); |
810 | break; | 810 | break; |
811 | case CEPH_MSG_STATFS_REPLY: | 811 | case CEPH_MSG_STATFS_REPLY: |
812 | return get_statfs_reply(con, hdr, skip); | 812 | return get_generic_reply(con, hdr, skip); |
813 | case CEPH_MSG_AUTH_REPLY: | 813 | case CEPH_MSG_AUTH_REPLY: |
814 | m = ceph_msg_get(monc->m_auth_reply); | 814 | m = ceph_msg_get(monc->m_auth_reply); |
815 | break; | 815 | break; |