@@ -156,7 +156,6 @@ static bool con_flag_test_and_set(struct ceph_connection *con,
156
156
/* Slab caches for frequently-allocated structures */
157
157
158
158
static struct kmem_cache * ceph_msg_cache ;
159
- static struct kmem_cache * ceph_msg_data_cache ;
160
159
161
160
/* static tag bytes (protocol control messages) */
162
161
static char tag_msg = CEPH_MSGR_TAG_MSG ;
@@ -235,23 +234,11 @@ static int ceph_msgr_slab_init(void)
235
234
if (!ceph_msg_cache )
236
235
return - ENOMEM ;
237
236
238
- BUG_ON (ceph_msg_data_cache );
239
- ceph_msg_data_cache = KMEM_CACHE (ceph_msg_data , 0 );
240
- if (ceph_msg_data_cache )
241
- return 0 ;
242
-
243
- kmem_cache_destroy (ceph_msg_cache );
244
- ceph_msg_cache = NULL ;
245
-
246
- return - ENOMEM ;
237
+ return 0 ;
247
238
}
248
239
249
240
static void ceph_msgr_slab_exit (void )
250
241
{
251
- BUG_ON (!ceph_msg_data_cache );
252
- kmem_cache_destroy (ceph_msg_data_cache );
253
- ceph_msg_data_cache = NULL ;
254
-
255
242
BUG_ON (!ceph_msg_cache );
256
243
kmem_cache_destroy (ceph_msg_cache );
257
244
ceph_msg_cache = NULL ;
@@ -1141,16 +1128,13 @@ static void __ceph_msg_data_cursor_init(struct ceph_msg_data_cursor *cursor)
1141
1128
static void ceph_msg_data_cursor_init (struct ceph_msg * msg , size_t length )
1142
1129
{
1143
1130
struct ceph_msg_data_cursor * cursor = & msg -> cursor ;
1144
- struct ceph_msg_data * data ;
1145
1131
1146
1132
BUG_ON (!length );
1147
1133
BUG_ON (length > msg -> data_length );
1148
- BUG_ON (list_empty ( & msg -> data ) );
1134
+ BUG_ON (! msg -> num_data_items );
1149
1135
1150
- cursor -> data_head = & msg -> data ;
1151
1136
cursor -> total_resid = length ;
1152
- data = list_first_entry (& msg -> data , struct ceph_msg_data , links );
1153
- cursor -> data = data ;
1137
+ cursor -> data = msg -> data ;
1154
1138
1155
1139
__ceph_msg_data_cursor_init (cursor );
1156
1140
}
@@ -1231,8 +1215,7 @@ static void ceph_msg_data_advance(struct ceph_msg_data_cursor *cursor,
1231
1215
1232
1216
if (!cursor -> resid && cursor -> total_resid ) {
1233
1217
WARN_ON (!cursor -> last_piece );
1234
- BUG_ON (list_is_last (& cursor -> data -> links , cursor -> data_head ));
1235
- cursor -> data = list_next_entry (cursor -> data , links );
1218
+ cursor -> data ++ ;
1236
1219
__ceph_msg_data_cursor_init (cursor );
1237
1220
new_piece = true;
1238
1221
}
@@ -1248,9 +1231,6 @@ static size_t sizeof_footer(struct ceph_connection *con)
1248
1231
1249
1232
static void prepare_message_data (struct ceph_msg * msg , u32 data_len )
1250
1233
{
1251
- BUG_ON (!msg );
1252
- BUG_ON (!data_len );
1253
-
1254
1234
/* Initialize data cursor */
1255
1235
1256
1236
ceph_msg_data_cursor_init (msg , (size_t )data_len );
@@ -1590,7 +1570,7 @@ static int write_partial_message_data(struct ceph_connection *con)
1590
1570
1591
1571
dout ("%s %p msg %p\n" , __func__ , con , msg );
1592
1572
1593
- if (list_empty ( & msg -> data ) )
1573
+ if (! msg -> num_data_items )
1594
1574
return - EINVAL ;
1595
1575
1596
1576
/*
@@ -2347,8 +2327,7 @@ static int read_partial_msg_data(struct ceph_connection *con)
2347
2327
u32 crc = 0 ;
2348
2328
int ret ;
2349
2329
2350
- BUG_ON (!msg );
2351
- if (list_empty (& msg -> data ))
2330
+ if (!msg -> num_data_items )
2352
2331
return - EIO ;
2353
2332
2354
2333
if (do_datacrc )
@@ -3256,32 +3235,16 @@ bool ceph_con_keepalive_expired(struct ceph_connection *con,
3256
3235
return false;
3257
3236
}
3258
3237
3259
- static struct ceph_msg_data * ceph_msg_data_create ( enum ceph_msg_data_type type )
3238
+ static struct ceph_msg_data * ceph_msg_data_add ( struct ceph_msg * msg )
3260
3239
{
3261
- struct ceph_msg_data * data ;
3262
-
3263
- if (WARN_ON (!ceph_msg_data_type_valid (type )))
3264
- return NULL ;
3265
-
3266
- data = kmem_cache_zalloc (ceph_msg_data_cache , GFP_NOFS );
3267
- if (!data )
3268
- return NULL ;
3269
-
3270
- data -> type = type ;
3271
- INIT_LIST_HEAD (& data -> links );
3272
-
3273
- return data ;
3240
+ BUG_ON (msg -> num_data_items >= msg -> max_data_items );
3241
+ return & msg -> data [msg -> num_data_items ++ ];
3274
3242
}
3275
3243
3276
3244
static void ceph_msg_data_destroy (struct ceph_msg_data * data )
3277
3245
{
3278
- if (!data )
3279
- return ;
3280
-
3281
- WARN_ON (!list_empty (& data -> links ));
3282
3246
if (data -> type == CEPH_MSG_DATA_PAGELIST )
3283
3247
ceph_pagelist_release (data -> pagelist );
3284
- kmem_cache_free (ceph_msg_data_cache , data );
3285
3248
}
3286
3249
3287
3250
void ceph_msg_data_add_pages (struct ceph_msg * msg , struct page * * pages ,
@@ -3292,13 +3255,12 @@ void ceph_msg_data_add_pages(struct ceph_msg *msg, struct page **pages,
3292
3255
BUG_ON (!pages );
3293
3256
BUG_ON (!length );
3294
3257
3295
- data = ceph_msg_data_create ( CEPH_MSG_DATA_PAGES );
3296
- BUG_ON (! data ) ;
3258
+ data = ceph_msg_data_add ( msg );
3259
+ data -> type = CEPH_MSG_DATA_PAGES ;
3297
3260
data -> pages = pages ;
3298
3261
data -> length = length ;
3299
3262
data -> alignment = alignment & ~PAGE_MASK ;
3300
3263
3301
- list_add_tail (& data -> links , & msg -> data );
3302
3264
msg -> data_length += length ;
3303
3265
}
3304
3266
EXPORT_SYMBOL (ceph_msg_data_add_pages );
@@ -3311,12 +3273,11 @@ void ceph_msg_data_add_pagelist(struct ceph_msg *msg,
3311
3273
BUG_ON (!pagelist );
3312
3274
BUG_ON (!pagelist -> length );
3313
3275
3314
- data = ceph_msg_data_create ( CEPH_MSG_DATA_PAGELIST );
3315
- BUG_ON (! data ) ;
3276
+ data = ceph_msg_data_add ( msg );
3277
+ data -> type = CEPH_MSG_DATA_PAGELIST ;
3316
3278
refcount_inc (& pagelist -> refcnt );
3317
3279
data -> pagelist = pagelist ;
3318
3280
3319
- list_add_tail (& data -> links , & msg -> data );
3320
3281
msg -> data_length += pagelist -> length ;
3321
3282
}
3322
3283
EXPORT_SYMBOL (ceph_msg_data_add_pagelist );
@@ -3327,12 +3288,11 @@ void ceph_msg_data_add_bio(struct ceph_msg *msg, struct ceph_bio_iter *bio_pos,
3327
3288
{
3328
3289
struct ceph_msg_data * data ;
3329
3290
3330
- data = ceph_msg_data_create ( CEPH_MSG_DATA_BIO );
3331
- BUG_ON (! data ) ;
3291
+ data = ceph_msg_data_add ( msg );
3292
+ data -> type = CEPH_MSG_DATA_BIO ;
3332
3293
data -> bio_pos = * bio_pos ;
3333
3294
data -> bio_length = length ;
3334
3295
3335
- list_add_tail (& data -> links , & msg -> data );
3336
3296
msg -> data_length += length ;
3337
3297
}
3338
3298
EXPORT_SYMBOL (ceph_msg_data_add_bio );
@@ -3343,11 +3303,10 @@ void ceph_msg_data_add_bvecs(struct ceph_msg *msg,
3343
3303
{
3344
3304
struct ceph_msg_data * data ;
3345
3305
3346
- data = ceph_msg_data_create ( CEPH_MSG_DATA_BVECS );
3347
- BUG_ON (! data ) ;
3306
+ data = ceph_msg_data_add ( msg );
3307
+ data -> type = CEPH_MSG_DATA_BVECS ;
3348
3308
data -> bvec_pos = * bvec_pos ;
3349
3309
3350
- list_add_tail (& data -> links , & msg -> data );
3351
3310
msg -> data_length += bvec_pos -> iter .bi_size ;
3352
3311
}
3353
3312
EXPORT_SYMBOL (ceph_msg_data_add_bvecs );
@@ -3356,8 +3315,8 @@ EXPORT_SYMBOL(ceph_msg_data_add_bvecs);
3356
3315
* construct a new message with given type, size
3357
3316
* the new msg has a ref count of 1.
3358
3317
*/
3359
- struct ceph_msg * ceph_msg_new (int type , int front_len , gfp_t flags ,
3360
- bool can_fail )
3318
+ struct ceph_msg * ceph_msg_new2 (int type , int front_len , int max_data_items ,
3319
+ gfp_t flags , bool can_fail )
3361
3320
{
3362
3321
struct ceph_msg * m ;
3363
3322
@@ -3371,7 +3330,6 @@ struct ceph_msg *ceph_msg_new(int type, int front_len, gfp_t flags,
3371
3330
3372
3331
INIT_LIST_HEAD (& m -> list_head );
3373
3332
kref_init (& m -> kref );
3374
- INIT_LIST_HEAD (& m -> data );
3375
3333
3376
3334
/* front */
3377
3335
if (front_len ) {
@@ -3386,6 +3344,15 @@ struct ceph_msg *ceph_msg_new(int type, int front_len, gfp_t flags,
3386
3344
}
3387
3345
m -> front_alloc_len = m -> front .iov_len = front_len ;
3388
3346
3347
+ if (max_data_items ) {
3348
+ m -> data = kmalloc_array (max_data_items , sizeof (* m -> data ),
3349
+ flags );
3350
+ if (!m -> data )
3351
+ goto out2 ;
3352
+
3353
+ m -> max_data_items = max_data_items ;
3354
+ }
3355
+
3389
3356
dout ("ceph_msg_new %p front %d\n" , m , front_len );
3390
3357
return m ;
3391
3358
@@ -3402,6 +3369,13 @@ struct ceph_msg *ceph_msg_new(int type, int front_len, gfp_t flags,
3402
3369
}
3403
3370
return NULL ;
3404
3371
}
3372
+ EXPORT_SYMBOL (ceph_msg_new2 );
3373
+
3374
+ struct ceph_msg * ceph_msg_new (int type , int front_len , gfp_t flags ,
3375
+ bool can_fail )
3376
+ {
3377
+ return ceph_msg_new2 (type , front_len , 0 , flags , can_fail );
3378
+ }
3405
3379
EXPORT_SYMBOL (ceph_msg_new );
3406
3380
3407
3381
/*
@@ -3497,13 +3471,14 @@ static void ceph_msg_free(struct ceph_msg *m)
3497
3471
{
3498
3472
dout ("%s %p\n" , __func__ , m );
3499
3473
kvfree (m -> front .iov_base );
3474
+ kfree (m -> data );
3500
3475
kmem_cache_free (ceph_msg_cache , m );
3501
3476
}
3502
3477
3503
3478
static void ceph_msg_release (struct kref * kref )
3504
3479
{
3505
3480
struct ceph_msg * m = container_of (kref , struct ceph_msg , kref );
3506
- struct ceph_msg_data * data , * next ;
3481
+ int i ;
3507
3482
3508
3483
dout ("%s %p\n" , __func__ , m );
3509
3484
WARN_ON (!list_empty (& m -> list_head ));
@@ -3516,11 +3491,8 @@ static void ceph_msg_release(struct kref *kref)
3516
3491
m -> middle = NULL ;
3517
3492
}
3518
3493
3519
- list_for_each_entry_safe (data , next , & m -> data , links ) {
3520
- list_del_init (& data -> links );
3521
- ceph_msg_data_destroy (data );
3522
- }
3523
- m -> data_length = 0 ;
3494
+ for (i = 0 ; i < m -> num_data_items ; i ++ )
3495
+ ceph_msg_data_destroy (& m -> data [i ]);
3524
3496
3525
3497
if (m -> pool )
3526
3498
ceph_msgpool_put (m -> pool , m );
0 commit comments