| @@ -2,14 +2,13 @@ · 1 unmodified line |
| 2 | /* | 2 | /* |
| 3 | * Copyright (C) 2024, Alibaba Cloud | 3 | * Copyright (C) 2024, Alibaba Cloud |
| 4 | */ | 4 | */ |
| | 5 | #include <linux/backing-file.h> |
| 5 | #include <linux/xxhash.h> | 6 | #include <linux/xxhash.h> |
| 6 | #include <linux/mount.h> | 7 | #include <linux/mount.h> |
| 7 | #include <linux/security.h> | 8 | #include <linux/security.h> |
| 8 | #include "internal.h" | 9 | #include "internal.h" |
| 9 | #include "xattr.h" | 10 | #include "xattr.h" |
| 10 | | 11 | |
| 11 | #include "../internal.h" | | |
| 12 | | | |
| 13 | static struct vfsmount *erofs_ishare_mnt; | 12 | static struct vfsmount *erofs_ishare_mnt; |
| 14 | | 13 | |
| 15 | static int erofs_ishare_iget5_eq(struct inode *inode, void *data) | 14 | static int erofs_ishare_iget5_eq(struct inode *inode, void *data) |
| @@ -33,10 +32,12 @@ static int erofs_ishare_iget5_set(struct inode *inode, void *data) · 17 unmodified lines |
| 33 | | 32 | |
| 34 | bool erofs_ishare_fill_inode(struct inode *inode) | 33 | bool erofs_ishare_fill_inode(struct inode *inode) |
| 35 | { | 34 | { |
| | 35 | static const struct file_operations empty_fops = {}; |
| 36 | struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb); | 36 | struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb); |
| 37 | const struct address_space_operations *aops; | 37 | const struct address_space_operations *aops; |
| 38 | struct erofs_inode *vi = EROFS_I(inode); | 38 | struct erofs_inode *vi = EROFS_I(inode); |
| 39 | struct erofs_inode_fingerprint fp; | 39 | struct erofs_inode_fingerprint fp; |
| | 40 | struct dentry *sd; |
| 40 | struct inode *si; | 41 | struct inode *si; |
| 41 | | 42 | |
| 42 | aops = erofs_get_aops(inode); | 43 | aops = erofs_get_aops(inode); |
| @@ -49,7 +50,9 @@ bool erofs_ishare_fill_inode(struct inode *inode) · 6 unmodified lines |
| 49 | xxh32(fp.opaque, fp.size, 0), | 50 | xxh32(fp.opaque, fp.size, 0), |
| 50 | erofs_ishare_iget5_eq, erofs_ishare_iget5_set, &fp); | 51 | erofs_ishare_iget5_eq, erofs_ishare_iget5_set, &fp); |
| 51 | if (si && (inode_state_read_once(si) & I_NEW)) { | 52 | if (si && (inode_state_read_once(si) & I_NEW)) { |
| | 53 | si->i_fop = &empty_fops; |
| 52 | si->i_mapping->a_ops = aops; | 54 | si->i_mapping->a_ops = aops; |
| | 55 | si->i_mode = 0444 | S_IFREG; |
| 53 | si->i_size = inode->i_size; | 56 | si->i_size = inode->i_size; |
| 54 | unlock_new_inode(si); | 57 | unlock_new_inode(si); |
| 55 | } else { | 58 | } else { |
| @@ -65,7 +68,10 @@ bool erofs_ishare_fill_inode(struct inode *inode) · 9 unmodified lines |
| 65 | return false; | 68 | return false; |
| 66 | } | 69 | } |
| 67 | } | 70 | } |
| 68 | vi->sharedinode = si; | 71 | sd = d_obtain_alias(si); /* disconnected denties for sharedinodes */ |
| | 72 | if (IS_ERR(sd)) |
| | 73 | return false; |
| | 74 | vi->sharedentry = sd; |
| 69 | INIT_LIST_HEAD(&vi->ishare_list); | 75 | INIT_LIST_HEAD(&vi->ishare_list); |
| 70 | spin_lock(&EROFS_I(si)->ishare_lock); | 76 | spin_lock(&EROFS_I(si)->ishare_lock); |
| 71 | list_add(&vi->ishare_list, &EROFS_I(si)->ishare_list); | 77 | list_add(&vi->ishare_list, &EROFS_I(si)->ishare_list); |
| @@ -75,48 +81,40 @@ bool erofs_ishare_fill_inode(struct inode *inode) · 3 unmodified lines |
| 75 | | 81 | |
| 76 | void erofs_ishare_free_inode(struct inode *inode) | 82 | void erofs_ishare_free_inode(struct inode *inode) |
| 77 | { | 83 | { |
| 78 | struct erofs_inode *vi = EROFS_I(inode); | 84 | struct erofs_inode *vi = EROFS_I(inode), *svi; |
| 79 | struct inode *sharedinode = vi->sharedinode; | | |
| 80 | | 85 | |
| 81 | if (!sharedinode) | 86 | if (!vi->sharedentry) |
| 82 | return; | 87 | return; |
| 83 | spin_lock(&EROFS_I(sharedinode)->ishare_lock); | 88 | svi = EROFS_I(d_inode(vi->sharedentry)); |
| | 89 | spin_lock(&svi->ishare_lock); |
| 84 | list_del(&vi->ishare_list); | 90 | list_del(&vi->ishare_list); |
| 85 | spin_unlock(&EROFS_I(sharedinode)->ishare_lock); | 91 | spin_unlock(&svi->ishare_lock); |
| 86 | iput(sharedinode); | 92 | dput(vi->sharedentry); |
| 87 | vi->sharedinode = NULL; | 93 | vi->sharedentry = NULL; |
| 88 | } | 94 | } |
| 89 | | 95 | |
| 90 | static int erofs_ishare_file_open(struct inode *inode, struct file *file) | 96 | static int erofs_ishare_file_open(struct inode *inode, struct file *file) |
| 91 | { | 97 | { |
| 92 | struct inode *sharedinode = EROFS_I(inode)->sharedinode; | 98 | struct path sharedpath = { |
| 93 | struct file *realfile; | 99 | .mnt = erofs_ishare_mnt, |
| | 100 | .dentry = EROFS_I(inode)->sharedentry, |
| | 101 | }; |
| | 102 | struct file *rf; |
| 94 | | 103 | |
| 95 | if (file->f_flags & O_DIRECT) | 104 | if (file->f_flags & O_DIRECT) |
| 96 | return -EINVAL; | 105 | return -EINVAL; |
| 97 | realfile = alloc_empty_backing_file(O_RDONLY|O_NOATIME, current_cred(), | 106 | |
| 98 | file); | 107 | rf = backing_file_open(file, file->f_flags | O_NOATIME, |
| 99 | if (IS_ERR(realfile)) | 108 | &sharedpath, current_cred()); |
| 100 | return PTR_ERR(realfile); | 109 | if (IS_ERR(rf)) |
| 101 | ihold(sharedinode); | 110 | return PTR_ERR(rf); |
| 102 | realfile->f_op = &erofs_file_fops; | 111 | file->private_data = rf; |
| 103 | realfile->f_inode = sharedinode; | | |
| 104 | realfile->f_mapping = sharedinode->i_mapping; | | |
| 105 | path_get(&file->f_path); | | |
| 106 | backing_file_set_user_path(realfile, &file->f_path); | | |
| 107 | | | |
| 108 | file_ra_state_init(&realfile->f_ra, file->f_mapping); | | |
| 109 | realfile->private_data = EROFS_I(inode); | | |
| 110 | file->private_data = realfile; | | |
| 111 | return 0; | 112 | return 0; |
| 112 | } | 113 | } |
| 113 | | 114 | |
| 114 | static int erofs_ishare_file_release(struct inode *inode, struct file *file) | 115 | static int erofs_ishare_file_release(struct inode *inode, struct file *file) |
| 115 | { | 116 | { |
| 116 | struct file *realfile = file->private_data; | 117 | fput(file->private_data); |
| 117 | | | |
| 118 | iput(realfile->f_inode); | | |
| 119 | fput(realfile); | | |
| 120 | file->private_data = NULL; | 118 | file->private_data = NULL; |
| 121 | return 0; | 119 | return 0; |
| 122 | } | 120 | } |