diff options
author | Alex Elder <elder@inktank.com> | 2013-03-01 19:00:16 -0500 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2013-05-02 00:16:55 -0400 |
commit | 437945094fed0deb1810e8da95465c8f26bc6f80 (patch) | |
tree | afd9e83b01b06bcad1e8933df3b990479bd558fa /include/linux/ceph | |
parent | f9e15777afd87585f2222dfd446c2e52deb65eba (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 'include/linux/ceph')
-rw-r--r-- | include/linux/ceph/messenger.h | 71 |
1 files changed, 51 insertions, 20 deletions
diff --git a/include/linux/ceph/messenger.h b/include/linux/ceph/messenger.h index fb2b18a20c13..5860dd0c2caf 100644 --- a/include/linux/ceph/messenger.h +++ b/include/linux/ceph/messenger.h | |||
@@ -64,12 +64,55 @@ struct ceph_messenger { | |||
64 | u32 required_features; | 64 | u32 required_features; |
65 | }; | 65 | }; |
66 | 66 | ||
67 | #define ceph_msg_has_pages(m) ((m)->p.pages != NULL) | 67 | #define ceph_msg_has_pages(m) ((m)->p.type == CEPH_MSG_DATA_PAGES) |
68 | #define ceph_msg_has_pagelist(m) ((m)->l.pagelist != NULL) | 68 | #define ceph_msg_has_pagelist(m) ((m)->l.type == CEPH_MSG_DATA_PAGELIST) |
69 | #ifdef CONFIG_BLOCK | 69 | #ifdef CONFIG_BLOCK |
70 | #define ceph_msg_has_bio(m) ((m)->b.bio != NULL) | 70 | #define ceph_msg_has_bio(m) ((m)->b.type == CEPH_MSG_DATA_BIO) |
71 | #endif /* CONFIG_BLOCK */ | 71 | #endif /* CONFIG_BLOCK */ |
72 | #define ceph_msg_has_trail(m) ((m)->t.trail != NULL) | 72 | #define ceph_msg_has_trail(m) ((m)->t.type == CEPH_MSG_DATA_PAGELIST) |
73 | |||
74 | enum ceph_msg_data_type { | ||
75 | CEPH_MSG_DATA_NONE, /* message contains no data payload */ | ||
76 | CEPH_MSG_DATA_PAGES, /* data source/destination is a page array */ | ||
77 | CEPH_MSG_DATA_PAGELIST, /* data source/destination is a pagelist */ | ||
78 | #ifdef CONFIG_BLOCK | ||
79 | CEPH_MSG_DATA_BIO, /* data source/destination is a bio list */ | ||
80 | #endif /* CONFIG_BLOCK */ | ||
81 | }; | ||
82 | |||
83 | static __inline__ bool ceph_msg_data_type_valid(enum ceph_msg_data_type type) | ||
84 | { | ||
85 | switch (type) { | ||
86 | case CEPH_MSG_DATA_NONE: | ||
87 | case CEPH_MSG_DATA_PAGES: | ||
88 | case CEPH_MSG_DATA_PAGELIST: | ||
89 | #ifdef CONFIG_BLOCK | ||
90 | case CEPH_MSG_DATA_BIO: | ||
91 | #endif /* CONFIG_BLOCK */ | ||
92 | return true; | ||
93 | default: | ||
94 | return false; | ||
95 | } | ||
96 | } | ||
97 | |||
98 | struct ceph_msg_data { | ||
99 | enum ceph_msg_data_type type; | ||
100 | union { | ||
101 | #ifdef CONFIG_BLOCK | ||
102 | struct { | ||
103 | struct bio *bio_iter; /* iterator */ | ||
104 | struct bio *bio; | ||
105 | unsigned int bio_seg; /* current seg in bio */ | ||
106 | }; | ||
107 | #endif /* CONFIG_BLOCK */ | ||
108 | struct { | ||
109 | struct page **pages; /* NOT OWNER. */ | ||
110 | size_t length; /* total # bytes */ | ||
111 | unsigned int alignment; /* first page */ | ||
112 | }; | ||
113 | struct ceph_pagelist *pagelist; | ||
114 | }; | ||
115 | }; | ||
73 | 116 | ||
74 | /* | 117 | /* |
75 | * a single message. it contains a header (src, dest, message type, etc.), | 118 | * a single message. it contains a header (src, dest, message type, etc.), |
@@ -83,24 +126,12 @@ struct ceph_msg { | |||
83 | struct ceph_buffer *middle; | 126 | struct ceph_buffer *middle; |
84 | 127 | ||
85 | /* data payload */ | 128 | /* data payload */ |
86 | struct { | 129 | struct ceph_msg_data p; /* pages */ |
87 | struct page **pages; /* NOT OWNER. */ | 130 | struct ceph_msg_data l; /* pagelist */ |
88 | size_t length; /* # data bytes in array */ | ||
89 | unsigned int alignment; /* first page */ | ||
90 | } p; | ||
91 | struct { | ||
92 | struct ceph_pagelist *pagelist; | ||
93 | } l; | ||
94 | #ifdef CONFIG_BLOCK | 131 | #ifdef CONFIG_BLOCK |
95 | struct { | 132 | struct ceph_msg_data b; /* bio */ |
96 | struct bio *bio_iter; /* iterator */ | ||
97 | struct bio *bio; | ||
98 | unsigned int bio_seg; /* current seg in bio */ | ||
99 | } b; | ||
100 | #endif /* CONFIG_BLOCK */ | 133 | #endif /* CONFIG_BLOCK */ |
101 | struct { | 134 | struct ceph_msg_data t; /* trail */ |
102 | struct ceph_pagelist *trail; /* trailing part of data */ | ||
103 | } t; | ||
104 | 135 | ||
105 | struct ceph_connection *con; | 136 | struct ceph_connection *con; |
106 | struct list_head list_head; /* links for connection lists */ | 137 | struct list_head list_head; /* links for connection lists */ |