@@ -288,17 +288,27 @@ static void dirent_init_casefolded_name(struct bkey_i_dirent *dirent,
288288}
289289
290290static struct bkey_i_dirent * dirent_create_key (struct btree_trans * trans ,
291+ const struct bch_hash_info * hash_info ,
291292 subvol_inum dir ,
292293 u8 type ,
293294 const struct qstr * name ,
294295 const struct qstr * cf_name ,
295296 u64 dst )
296297{
297298 struct bkey_i_dirent * dirent ;
299+ struct qstr _cf_name ;
298300
299301 if (name -> len > BCH_NAME_MAX )
300302 return ERR_PTR (- ENAMETOOLONG );
301303
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+
302312 dirent = dirent_alloc_key (trans , dir , type , name -> len , cf_name ? cf_name -> len : 0 , dst );
303313 if (IS_ERR (dirent ))
304314 return dirent ;
@@ -324,7 +334,7 @@ int bch2_dirent_create_snapshot(struct btree_trans *trans,
324334 struct bkey_i_dirent * dirent ;
325335 int ret ;
326336
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 );
328338 ret = PTR_ERR_OR_ZERO (dirent );
329339 if (ret )
330340 return ret ;
@@ -333,8 +343,7 @@ int bch2_dirent_create_snapshot(struct btree_trans *trans,
333343 dirent -> k .p .snapshot = snapshot ;
334344
335345 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 );
338347 * dir_offset = dirent -> k .p .offset ;
339348
340349 return ret ;
@@ -344,28 +353,16 @@ int bch2_dirent_create(struct btree_trans *trans, subvol_inum dir,
344353 const struct bch_hash_info * hash_info ,
345354 u8 type , const struct qstr * name , u64 dst_inum ,
346355 u64 * dir_offset ,
347- u64 * i_size ,
348356 enum btree_iter_update_trigger_flags flags )
349357{
350358 struct bkey_i_dirent * dirent ;
351359 int ret ;
352360
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 );
363362 ret = PTR_ERR_OR_ZERO (dirent );
364363 if (ret )
365364 return ret ;
366365
367- * i_size += bkey_bytes (& dirent -> k );
368-
369366 ret = bch2_hash_set (trans , bch2_dirent_hash_desc , hash_info ,
370367 dir , & dirent -> k_i , flags );
371368 * dir_offset = dirent -> k .p .offset ;
@@ -466,7 +463,7 @@ int bch2_dirent_rename(struct btree_trans *trans,
466463 * src_offset = dst_iter .pos .offset ;
467464
468465 /* 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 ,
470467 dst_hash -> cf_encoding ? & dst_name_lookup : NULL , 0 );
471468 ret = PTR_ERR_OR_ZERO (new_dst );
472469 if (ret )
@@ -477,7 +474,7 @@ int bch2_dirent_rename(struct btree_trans *trans,
477474
478475 /* Create new src key: */
479476 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 ,
481478 src_hash -> cf_encoding ? & src_name_lookup : NULL , 0 );
482479 ret = PTR_ERR_OR_ZERO (new_src );
483480 if (ret )
0 commit comments