@@ -985,8 +985,10 @@ static bool ceph_msg_data_pagelist_advance(struct ceph_msg_data_cursor *cursor,
985985static void ceph_msg_data_cursor_init (struct ceph_msg * msg , size_t length )
986986{
987987 struct ceph_msg_data_cursor * cursor = & msg -> cursor ;
988+ struct ceph_msg_data * data ;
988989
989- cursor -> data = msg -> data ;
990+ data = list_first_entry (& msg -> data , struct ceph_msg_data , links );
991+ cursor -> data = data ;
990992 switch (cursor -> data -> type ) {
991993 case CEPH_MSG_DATA_PAGELIST :
992994 ceph_msg_data_pagelist_cursor_init (cursor , length );
@@ -1410,7 +1412,7 @@ static int write_partial_message_data(struct ceph_connection *con)
14101412
14111413 dout ("%s %p msg %p\n" , __func__ , con , msg );
14121414
1413- if (WARN_ON (! msg -> data ))
1415+ if (list_empty ( & msg -> data ))
14141416 return - EINVAL ;
14151417
14161418 /*
@@ -2111,7 +2113,7 @@ static int read_partial_msg_data(struct ceph_connection *con)
21112113 int ret ;
21122114
21132115 BUG_ON (!msg );
2114- if (! msg -> data )
2116+ if (list_empty ( & msg -> data ) )
21152117 return - EIO ;
21162118
21172119 if (do_datacrc )
@@ -2963,6 +2965,7 @@ static struct ceph_msg_data *ceph_msg_data_create(enum ceph_msg_data_type type)
29632965 data = kzalloc (sizeof (* data ), GFP_NOFS );
29642966 if (data )
29652967 data -> type = type ;
2968+ INIT_LIST_HEAD (& data -> links );
29662969
29672970 return data ;
29682971}
@@ -2972,6 +2975,7 @@ static void ceph_msg_data_destroy(struct ceph_msg_data *data)
29722975 if (!data )
29732976 return ;
29742977
2978+ WARN_ON (!list_empty (& data -> links ));
29752979 if (data -> type == CEPH_MSG_DATA_PAGELIST ) {
29762980 ceph_pagelist_release (data -> pagelist );
29772981 kfree (data -> pagelist );
@@ -2987,16 +2991,17 @@ void ceph_msg_data_set_pages(struct ceph_msg *msg, struct page **pages,
29872991 BUG_ON (!pages );
29882992 BUG_ON (!length );
29892993 BUG_ON (msg -> data_length );
2990- BUG_ON (msg -> data != NULL );
2994+ BUG_ON (! list_empty ( & msg -> data ) );
29912995
29922996 data = ceph_msg_data_create (CEPH_MSG_DATA_PAGES );
29932997 BUG_ON (!data );
29942998 data -> pages = pages ;
29952999 data -> length = length ;
29963000 data -> alignment = alignment & ~PAGE_MASK ;
29973001
2998- msg -> data = data ;
2999- msg -> data_length = length ;
3002+ BUG_ON (!list_empty (& msg -> data ));
3003+ list_add_tail (& data -> links , & msg -> data );
3004+ msg -> data_length += length ;
30003005}
30013006EXPORT_SYMBOL (ceph_msg_data_set_pages );
30023007
@@ -3008,14 +3013,14 @@ void ceph_msg_data_set_pagelist(struct ceph_msg *msg,
30083013 BUG_ON (!pagelist );
30093014 BUG_ON (!pagelist -> length );
30103015 BUG_ON (msg -> data_length );
3011- BUG_ON (msg -> data != NULL );
3016+ BUG_ON (! list_empty ( & msg -> data ) );
30123017
30133018 data = ceph_msg_data_create (CEPH_MSG_DATA_PAGELIST );
30143019 BUG_ON (!data );
30153020 data -> pagelist = pagelist ;
30163021
3017- msg -> data = data ;
3018- msg -> data_length = pagelist -> length ;
3022+ list_add_tail ( & data -> links , & msg -> data ) ;
3023+ msg -> data_length + = pagelist -> length ;
30193024}
30203025EXPORT_SYMBOL (ceph_msg_data_set_pagelist );
30213026
@@ -3027,15 +3032,15 @@ void ceph_msg_data_set_bio(struct ceph_msg *msg, struct bio *bio,
30273032
30283033 BUG_ON (!bio );
30293034 BUG_ON (msg -> data_length );
3030- BUG_ON (msg -> data != NULL );
3035+ BUG_ON (! list_empty ( & msg -> data ) );
30313036
30323037 data = ceph_msg_data_create (CEPH_MSG_DATA_BIO );
30333038 BUG_ON (!data );
30343039 data -> bio = bio ;
30353040 data -> bio_length = length ;
30363041
3037- msg -> data = data ;
3038- msg -> data_length = length ;
3042+ list_add_tail ( & data -> links , & msg -> data ) ;
3043+ msg -> data_length + = length ;
30393044}
30403045EXPORT_SYMBOL (ceph_msg_data_set_bio );
30413046#endif /* CONFIG_BLOCK */
@@ -3059,6 +3064,7 @@ struct ceph_msg *ceph_msg_new(int type, int front_len, gfp_t flags,
30593064
30603065 INIT_LIST_HEAD (& m -> list_head );
30613066 kref_init (& m -> kref );
3067+ INIT_LIST_HEAD (& m -> data );
30623068
30633069 /* front */
30643070 m -> front_max = front_len ;
@@ -3204,6 +3210,9 @@ void ceph_msg_kfree(struct ceph_msg *m)
32043210void ceph_msg_last_put (struct kref * kref )
32053211{
32063212 struct ceph_msg * m = container_of (kref , struct ceph_msg , kref );
3213+ LIST_HEAD (data );
3214+ struct list_head * links ;
3215+ struct list_head * next ;
32073216
32083217 dout ("ceph_msg_put last one on %p\n" , m );
32093218 WARN_ON (!list_empty (& m -> list_head ));
@@ -3213,8 +3222,15 @@ void ceph_msg_last_put(struct kref *kref)
32133222 ceph_buffer_put (m -> middle );
32143223 m -> middle = NULL ;
32153224 }
3216- ceph_msg_data_destroy (m -> data );
3217- m -> data = NULL ;
3225+
3226+ list_splice_init (& m -> data , & data );
3227+ list_for_each_safe (links , next , & data ) {
3228+ struct ceph_msg_data * data ;
3229+
3230+ data = list_entry (links , struct ceph_msg_data , links );
3231+ list_del_init (links );
3232+ ceph_msg_data_destroy (data );
3233+ }
32183234 m -> data_length = 0 ;
32193235
32203236 if (m -> pool )
@@ -3227,7 +3243,7 @@ EXPORT_SYMBOL(ceph_msg_last_put);
32273243void ceph_msg_dump (struct ceph_msg * msg )
32283244{
32293245 pr_debug ("msg_dump %p (front_max %d length %zd)\n" , msg ,
3230- msg -> front_max , msg -> data -> length );
3246+ msg -> front_max , msg -> data_length );
32313247 print_hex_dump (KERN_DEBUG , "header: " ,
32323248 DUMP_PREFIX_OFFSET , 16 , 1 ,
32333249 & msg -> hdr , sizeof (msg -> hdr ), true);
0 commit comments