aboutsummaryrefslogtreecommitdiffstats
path: root/net/ceph/messenger.c
diff options
context:
space:
mode:
authorAlex Elder <elder@inktank.com>2013-03-01 19:00:16 -0500
committerSage Weil <sage@inktank.com>2013-05-02 00:16:55 -0400
commit437945094fed0deb1810e8da95465c8f26bc6f80 (patch)
treeafd9e83b01b06bcad1e8933df3b990479bd558fa /net/ceph/messenger.c
parentf9e15777afd87585f2222dfd446c2e52deb65eba (diff)
libceph: abstract message data
Group the types of message data into an abstract structure with a type indicator and a union containing fields appropriate to the type of data it represents. Use this to represent the pages, pagelist, bio, and trail in a ceph message. Verify message data is of type NONE in ceph_msg_data_set_*() routines. Since information about message data of type NONE really should not be interpreted, get rid of the other assertions in those functions. Signed-off-by: Alex Elder <elder@inktank.com> Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
Diffstat (limited to 'net/ceph/messenger.c')
-rw-r--r--net/ceph/messenger.c33
1 files changed, 23 insertions, 10 deletions
diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
index f485455f05a8..f256b4b174ad 100644
--- a/net/ceph/messenger.c
+++ b/net/ceph/messenger.c
@@ -1054,7 +1054,7 @@ static void out_msg_pos_next(struct ceph_connection *con, struct page *page,
1054 msg_pos->did_page_crc = false; 1054 msg_pos->did_page_crc = false;
1055 if (in_trail) { 1055 if (in_trail) {
1056 BUG_ON(!ceph_msg_has_trail(msg)); 1056 BUG_ON(!ceph_msg_has_trail(msg));
1057 list_rotate_left(&msg->t.trail->head); 1057 list_rotate_left(&msg->t.pagelist->head);
1058 } else if (ceph_msg_has_pagelist(msg)) { 1058 } else if (ceph_msg_has_pagelist(msg)) {
1059 list_rotate_left(&msg->l.pagelist->head); 1059 list_rotate_left(&msg->l.pagelist->head);
1060#ifdef CONFIG_BLOCK 1060#ifdef CONFIG_BLOCK
@@ -1120,7 +1120,7 @@ static int write_partial_message_data(struct ceph_connection *con)
1120 size_t trail_off = data_len; 1120 size_t trail_off = data_len;
1121 1121
1122 if (ceph_msg_has_trail(msg)) { 1122 if (ceph_msg_has_trail(msg)) {
1123 trail_len = msg->t.trail->length; 1123 trail_len = msg->t.pagelist->length;
1124 trail_off -= trail_len; 1124 trail_off -= trail_len;
1125 } 1125 }
1126 1126
@@ -1149,7 +1149,7 @@ static int write_partial_message_data(struct ceph_connection *con)
1149 if (in_trail) { 1149 if (in_trail) {
1150 BUG_ON(!ceph_msg_has_trail(msg)); 1150 BUG_ON(!ceph_msg_has_trail(msg));
1151 total_max_write = data_len - msg_pos->data_pos; 1151 total_max_write = data_len - msg_pos->data_pos;
1152 page = list_first_entry(&msg->t.trail->head, 1152 page = list_first_entry(&msg->t.pagelist->head,
1153 struct page, lru); 1153 struct page, lru);
1154 } else if (ceph_msg_has_pages(msg)) { 1154 } else if (ceph_msg_has_pages(msg)) {
1155 page = msg->p.pages[msg_pos->page]; 1155 page = msg->p.pages[msg_pos->page];
@@ -2736,14 +2736,19 @@ void ceph_con_keepalive(struct ceph_connection *con)
2736} 2736}
2737EXPORT_SYMBOL(ceph_con_keepalive); 2737EXPORT_SYMBOL(ceph_con_keepalive);
2738 2738
2739static void ceph_msg_data_init(struct ceph_msg_data *data)
2740{
2741 data->type = CEPH_MSG_DATA_NONE;
2742}
2743
2739void ceph_msg_data_set_pages(struct ceph_msg *msg, struct page **pages, 2744void ceph_msg_data_set_pages(struct ceph_msg *msg, struct page **pages,
2740 size_t length, size_t alignment) 2745 size_t length, size_t alignment)
2741{ 2746{
2742 BUG_ON(!pages); 2747 BUG_ON(!pages);
2743 BUG_ON(!length); 2748 BUG_ON(!length);
2744 BUG_ON(msg->p.pages); 2749 BUG_ON(msg->p.type != CEPH_MSG_DATA_NONE);
2745 BUG_ON(msg->p.length);
2746 2750
2751 msg->p.type = CEPH_MSG_DATA_PAGES;
2747 msg->p.pages = pages; 2752 msg->p.pages = pages;
2748 msg->p.length = length; 2753 msg->p.length = length;
2749 msg->p.alignment = alignment & ~PAGE_MASK; 2754 msg->p.alignment = alignment & ~PAGE_MASK;
@@ -2755,8 +2760,9 @@ void ceph_msg_data_set_pagelist(struct ceph_msg *msg,
2755{ 2760{
2756 BUG_ON(!pagelist); 2761 BUG_ON(!pagelist);
2757 BUG_ON(!pagelist->length); 2762 BUG_ON(!pagelist->length);
2758 BUG_ON(msg->l.pagelist); 2763 BUG_ON(msg->l.type != CEPH_MSG_DATA_NONE);
2759 2764
2765 msg->l.type = CEPH_MSG_DATA_PAGELIST;
2760 msg->l.pagelist = pagelist; 2766 msg->l.pagelist = pagelist;
2761} 2767}
2762EXPORT_SYMBOL(ceph_msg_data_set_pagelist); 2768EXPORT_SYMBOL(ceph_msg_data_set_pagelist);
@@ -2764,8 +2770,9 @@ EXPORT_SYMBOL(ceph_msg_data_set_pagelist);
2764void ceph_msg_data_set_bio(struct ceph_msg *msg, struct bio *bio) 2770void ceph_msg_data_set_bio(struct ceph_msg *msg, struct bio *bio)
2765{ 2771{
2766 BUG_ON(!bio); 2772 BUG_ON(!bio);
2767 BUG_ON(msg->b.bio); 2773 BUG_ON(msg->b.type != CEPH_MSG_DATA_NONE);
2768 2774
2775 msg->b.type = CEPH_MSG_DATA_BIO;
2769 msg->b.bio = bio; 2776 msg->b.bio = bio;
2770} 2777}
2771EXPORT_SYMBOL(ceph_msg_data_set_bio); 2778EXPORT_SYMBOL(ceph_msg_data_set_bio);
@@ -2774,9 +2781,10 @@ void ceph_msg_data_set_trail(struct ceph_msg *msg, struct ceph_pagelist *trail)
2774{ 2781{
2775 BUG_ON(!trail); 2782 BUG_ON(!trail);
2776 BUG_ON(!trail->length); 2783 BUG_ON(!trail->length);
2777 BUG_ON(msg->t.trail); 2784 BUG_ON(msg->b.type != CEPH_MSG_DATA_NONE);
2778 2785
2779 msg->t.trail = trail; 2786 msg->t.type = CEPH_MSG_DATA_PAGELIST;
2787 msg->t.pagelist = trail;
2780} 2788}
2781EXPORT_SYMBOL(ceph_msg_data_set_trail); 2789EXPORT_SYMBOL(ceph_msg_data_set_trail);
2782 2790
@@ -2800,6 +2808,11 @@ struct ceph_msg *ceph_msg_new(int type, int front_len, gfp_t flags,
2800 INIT_LIST_HEAD(&m->list_head); 2808 INIT_LIST_HEAD(&m->list_head);
2801 kref_init(&m->kref); 2809 kref_init(&m->kref);
2802 2810
2811 ceph_msg_data_init(&m->p);
2812 ceph_msg_data_init(&m->l);
2813 ceph_msg_data_init(&m->b);
2814 ceph_msg_data_init(&m->t);
2815
2803 /* front */ 2816 /* front */
2804 m->front_max = front_len; 2817 m->front_max = front_len;
2805 if (front_len) { 2818 if (front_len) {
@@ -2965,7 +2978,7 @@ void ceph_msg_last_put(struct kref *kref)
2965 } 2978 }
2966 2979
2967 if (ceph_msg_has_trail(m)) 2980 if (ceph_msg_has_trail(m))
2968 m->t.trail = NULL; 2981 m->t.pagelist = NULL;
2969 2982
2970 if (m->pool) 2983 if (m->pool)
2971 ceph_msgpool_put(m->pool, m); 2984 ceph_msgpool_put(m->pool, m);