@@ -288,17 +288,27 @@ static void dirent_init_casefolded_name(struct bkey_i_dirent *dirent,
288
288
}
289
289
290
290
static struct bkey_i_dirent * dirent_create_key (struct btree_trans * trans ,
291
+ const struct bch_hash_info * hash_info ,
291
292
subvol_inum dir ,
292
293
u8 type ,
293
294
const struct qstr * name ,
294
295
const struct qstr * cf_name ,
295
296
u64 dst )
296
297
{
297
298
struct bkey_i_dirent * dirent ;
299
+ struct qstr _cf_name ;
298
300
299
301
if (name -> len > BCH_NAME_MAX )
300
302
return ERR_PTR (- ENAMETOOLONG );
301
303
304
+ if (hash_info -> cf_encoding && !cf_name ) {
305
+ int ret = bch2_casefold (trans , hash_info , name , & _cf_name );
306
+ if (ret )
307
+ return ERR_PTR (ret );
308
+
309
+ cf_name = & _cf_name ;
310
+ }
311
+
302
312
dirent = dirent_alloc_key (trans , dir , type , name -> len , cf_name ? cf_name -> len : 0 , dst );
303
313
if (IS_ERR (dirent ))
304
314
return dirent ;
@@ -324,7 +334,7 @@ int bch2_dirent_create_snapshot(struct btree_trans *trans,
324
334
struct bkey_i_dirent * dirent ;
325
335
int ret ;
326
336
327
- dirent = dirent_create_key (trans , dir_inum , type , name , NULL , dst_inum );
337
+ dirent = dirent_create_key (trans , hash_info , dir_inum , type , name , NULL , dst_inum );
328
338
ret = PTR_ERR_OR_ZERO (dirent );
329
339
if (ret )
330
340
return ret ;
@@ -333,8 +343,7 @@ int bch2_dirent_create_snapshot(struct btree_trans *trans,
333
343
dirent -> k .p .snapshot = snapshot ;
334
344
335
345
ret = bch2_hash_set_in_snapshot (trans , bch2_dirent_hash_desc , hash_info ,
336
- dir_inum , snapshot , & dirent -> k_i ,
337
- flags |BTREE_UPDATE_internal_snapshot_node );
346
+ dir_inum , snapshot , & dirent -> k_i , flags );
338
347
* dir_offset = dirent -> k .p .offset ;
339
348
340
349
return ret ;
@@ -344,28 +353,16 @@ int bch2_dirent_create(struct btree_trans *trans, subvol_inum dir,
344
353
const struct bch_hash_info * hash_info ,
345
354
u8 type , const struct qstr * name , u64 dst_inum ,
346
355
u64 * dir_offset ,
347
- u64 * i_size ,
348
356
enum btree_iter_update_trigger_flags flags )
349
357
{
350
358
struct bkey_i_dirent * dirent ;
351
359
int ret ;
352
360
353
- if (hash_info -> cf_encoding ) {
354
- struct qstr cf_name ;
355
- ret = bch2_casefold (trans , hash_info , name , & cf_name );
356
- if (ret )
357
- return ret ;
358
- dirent = dirent_create_key (trans , dir , type , name , & cf_name , dst_inum );
359
- } else {
360
- dirent = dirent_create_key (trans , dir , type , name , NULL , dst_inum );
361
- }
362
-
361
+ dirent = dirent_create_key (trans , hash_info , dir , type , name , NULL , dst_inum );
363
362
ret = PTR_ERR_OR_ZERO (dirent );
364
363
if (ret )
365
364
return ret ;
366
365
367
- * i_size += bkey_bytes (& dirent -> k );
368
-
369
366
ret = bch2_hash_set (trans , bch2_dirent_hash_desc , hash_info ,
370
367
dir , & dirent -> k_i , flags );
371
368
* dir_offset = dirent -> k .p .offset ;
@@ -466,7 +463,7 @@ int bch2_dirent_rename(struct btree_trans *trans,
466
463
* src_offset = dst_iter .pos .offset ;
467
464
468
465
/* Create new dst key: */
469
- new_dst = dirent_create_key (trans , dst_dir , 0 , dst_name ,
466
+ new_dst = dirent_create_key (trans , dst_hash , dst_dir , 0 , dst_name ,
470
467
dst_hash -> cf_encoding ? & dst_name_lookup : NULL , 0 );
471
468
ret = PTR_ERR_OR_ZERO (new_dst );
472
469
if (ret )
@@ -477,7 +474,7 @@ int bch2_dirent_rename(struct btree_trans *trans,
477
474
478
475
/* Create new src key: */
479
476
if (mode == BCH_RENAME_EXCHANGE ) {
480
- new_src = dirent_create_key (trans , src_dir , 0 , src_name ,
477
+ new_src = dirent_create_key (trans , src_hash , src_dir , 0 , src_name ,
481
478
src_hash -> cf_encoding ? & src_name_lookup : NULL , 0 );
482
479
ret = PTR_ERR_OR_ZERO (new_src );
483
480
if (ret )
0 commit comments