@@ -434,29 +434,29 @@ struct ovl_fh *ovl_encode_real_fh(struct ovl_fs *ofs, struct dentry *real,
434434 return ERR_PTR (err );
435435}
436436
437- int ovl_set_origin (struct ovl_fs * ofs , struct dentry * lower ,
438- struct dentry * upper )
437+ struct ovl_fh * ovl_get_origin_fh (struct ovl_fs * ofs , struct dentry * origin )
439438{
440- const struct ovl_fh * fh = NULL ;
441- int err ;
442-
443439 /*
444440 * When lower layer doesn't support export operations store a 'null' fh,
445441 * so we can use the overlay.origin xattr to distignuish between a copy
446442 * up and a pure upper inode.
447443 */
448- if (ovl_can_decode_fh (lower -> d_sb )) {
449- fh = ovl_encode_real_fh (ofs , lower , false);
450- if (IS_ERR (fh ))
451- return PTR_ERR (fh );
452- }
444+ if (!ovl_can_decode_fh (origin -> d_sb ))
445+ return NULL ;
446+
447+ return ovl_encode_real_fh (ofs , origin , false);
448+ }
449+
450+ int ovl_set_origin_fh (struct ovl_fs * ofs , const struct ovl_fh * fh ,
451+ struct dentry * upper )
452+ {
453+ int err ;
453454
454455 /*
455456 * Do not fail when upper doesn't support xattrs.
456457 */
457458 err = ovl_check_setxattr (ofs , upper , OVL_XATTR_ORIGIN , fh -> buf ,
458459 fh ? fh -> fb .len : 0 , 0 );
459- kfree (fh );
460460
461461 /* Ignore -EPERM from setting "user.*" on symlink/special */
462462 return err == - EPERM ? 0 : err ;
@@ -484,7 +484,7 @@ static int ovl_set_upper_fh(struct ovl_fs *ofs, struct dentry *upper,
484484 *
485485 * Caller must hold i_mutex on indexdir.
486486 */
487- static int ovl_create_index (struct dentry * dentry , struct dentry * origin ,
487+ static int ovl_create_index (struct dentry * dentry , const struct ovl_fh * fh ,
488488 struct dentry * upper )
489489{
490490 struct ovl_fs * ofs = OVL_FS (dentry -> d_sb );
@@ -510,7 +510,7 @@ static int ovl_create_index(struct dentry *dentry, struct dentry *origin,
510510 if (WARN_ON (ovl_test_flag (OVL_INDEX , d_inode (dentry ))))
511511 return - EIO ;
512512
513- err = ovl_get_index_name ( ofs , origin , & name );
513+ err = ovl_get_index_name_fh ( fh , & name );
514514 if (err )
515515 return err ;
516516
@@ -549,6 +549,7 @@ struct ovl_copy_up_ctx {
549549 struct dentry * destdir ;
550550 struct qstr destname ;
551551 struct dentry * workdir ;
552+ const struct ovl_fh * origin_fh ;
552553 bool origin ;
553554 bool indexed ;
554555 bool metacopy ;
@@ -649,7 +650,7 @@ static int ovl_copy_up_metadata(struct ovl_copy_up_ctx *c, struct dentry *temp)
649650 * hard link.
650651 */
651652 if (c -> origin ) {
652- err = ovl_set_origin (ofs , c -> lowerpath . dentry , temp );
653+ err = ovl_set_origin_fh (ofs , c -> origin_fh , temp );
653654 if (err )
654655 return err ;
655656 }
@@ -772,7 +773,7 @@ static int ovl_copy_up_workdir(struct ovl_copy_up_ctx *c)
772773 goto cleanup ;
773774
774775 if (S_ISDIR (c -> stat .mode ) && c -> indexed ) {
775- err = ovl_create_index (c -> dentry , c -> lowerpath . dentry , temp );
776+ err = ovl_create_index (c -> dentry , c -> origin_fh , temp );
776777 if (err )
777778 goto cleanup ;
778779 }
@@ -890,6 +891,8 @@ static int ovl_do_copy_up(struct ovl_copy_up_ctx *c)
890891{
891892 int err ;
892893 struct ovl_fs * ofs = OVL_FS (c -> dentry -> d_sb );
894+ struct dentry * origin = c -> lowerpath .dentry ;
895+ struct ovl_fh * fh = NULL ;
893896 bool to_index = false;
894897
895898 /*
@@ -906,17 +909,25 @@ static int ovl_do_copy_up(struct ovl_copy_up_ctx *c)
906909 to_index = true;
907910 }
908911
909- if (S_ISDIR (c -> stat .mode ) || c -> stat .nlink == 1 || to_index )
912+ if (S_ISDIR (c -> stat .mode ) || c -> stat .nlink == 1 || to_index ) {
913+ fh = ovl_get_origin_fh (ofs , origin );
914+ if (IS_ERR (fh ))
915+ return PTR_ERR (fh );
916+
917+ /* origin_fh may be NULL */
918+ c -> origin_fh = fh ;
910919 c -> origin = true;
920+ }
911921
912922 if (to_index ) {
913923 c -> destdir = ovl_indexdir (c -> dentry -> d_sb );
914- err = ovl_get_index_name (ofs , c -> lowerpath . dentry , & c -> destname );
924+ err = ovl_get_index_name (ofs , origin , & c -> destname );
915925 if (err )
916- return err ;
926+ goto out_free_fh ;
917927 } else if (WARN_ON (!c -> parent )) {
918928 /* Disconnected dentry must be copied up to index dir */
919- return - EIO ;
929+ err = - EIO ;
930+ goto out_free_fh ;
920931 } else {
921932 /*
922933 * Mark parent "impure" because it may now contain non-pure
@@ -926,7 +937,7 @@ static int ovl_do_copy_up(struct ovl_copy_up_ctx *c)
926937 err = ovl_set_impure (c -> parent , c -> destdir );
927938 ovl_end_write (c -> dentry );
928939 if (err )
929- return err ;
940+ goto out_free_fh ;
930941 }
931942
932943 /* Should we copyup with O_TMPFILE or with workdir? */
@@ -960,6 +971,8 @@ static int ovl_do_copy_up(struct ovl_copy_up_ctx *c)
960971out :
961972 if (to_index )
962973 kfree (c -> destname .name );
974+ out_free_fh :
975+ kfree (fh );
963976 return err ;
964977}
965978
0 commit comments