16
16
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
/* $Id: i_op.c,v 1.58 2008/03/31 07:42:17 sfjro Exp $ */
20
* inode operations (except add/del/rename)
22
* $Id: i_op.c,v 1.60 2008/04/13 23:42:10 sfjro Exp $
21
25
//#include <linux/fs.h>
22
26
//#include <linux/namei.h>
23
27
#include <linux/mm.h>
24
#include <linux/security.h>
27
#ifdef CONFIG_AUFS_DLGT
28
struct security_inode_permission_args {
30
struct inode *h_inode;
32
struct nameidata *fake_nd;
35
static void call_security_inode_permission(void *args)
37
struct security_inode_permission_args *a = args;
38
LKTRTrace("fsuid %d\n", current->fsuid);
39
*a->errp = security_inode_permission(a->h_inode, a->mask, a->fake_nd);
41
#endif /* CONFIG_AUFS_DLGT */
43
30
static int h_permission(struct inode *h_inode, int mask,
44
31
struct nameidata *fake_nd, int brperm, int dlgt)
75
#ifndef CONFIG_AUFS_DLGT
76
err = security_inode_permission(h_inode, mask, fake_nd);
79
err = security_inode_permission(h_inode, mask,
83
struct security_inode_permission_args args = {
89
wkq_err = au_wkq_wait(call_security_inode_permission,
91
if (unlikely(wkq_err))
94
#endif /* CONFIG_AUFS_DLGT */
62
err = au_security_inode_permission(h_inode, mask, fake_nd,
188
157
sb = inode->i_sb;
189
158
locked = silly_lock(inode, nd);
190
dlgt = au_need_dlgt(sb);
159
mnt_flags = au_mntflags(sb);
160
dlgt = !!au_opt_test_dlgt(mnt_flags);
194
if (/* unlikely */(nondir || write_mask || au_need_dirperm1(sb))) {
164
if (/* unlikely */(nondir || write_mask
165
|| au_opt_test_dirperm1(mnt_flags))) {
195
166
h_inode = au_h_iptr(inode);
196
167
AuDebugOn(!h_inode
197
168
|| ((h_inode->i_mode & S_IFMT)
198
169
!= (inode->i_mode & S_IFMT)));
200
bindex = ibstart(inode);
171
bindex = au_ibstart(inode);
201
172
p = au_fake_dm(&fake_nd, nd, sb, bindex);
202
173
/* actual test will be delegated to LSM */
206
177
LKTRTrace("b%d\n", bindex);
207
178
err = h_permission(h_inode, mask, p,
208
sbr_perm(sb, bindex), dlgt);
179
au_sbr_perm(sb, bindex), dlgt);
209
180
au_fake_dm_release(p);
211
182
if (write_mask && !err) {
212
183
/* test whether the upper writable branch exists */
214
185
for (; bindex >= 0; bindex--)
215
if (!br_rdonly(stobr(sb, bindex))) {
186
if (!au_br_rdonly(au_sbr(sb, bindex))) {
237
208
LKTRTrace("b%d\n", bindex);
238
209
err = h_permission(h_inode, mask, p,
239
sbr_perm(sb, bindex), dlgt);
210
au_sbr_perm(sb, bindex), dlgt);
240
211
au_fake_dm_release(p);
272
243
if (unlikely(err))
275
ndp = au_dup_nd(stosi(dir->i_sb), &tmp_nd, nd);
276
npositive = au_lkup_dentry(dentry, dbstart(parent), /*type*/0, ndp);
246
ndp = au_dup_nd(au_sbi(dir->i_sb), &tmp_nd, nd);
247
npositive = au_lkup_dentry(dentry, au_dbstart(parent), /*type*/0, ndp);
279
250
ret = ERR_PTR(err);
337
308
struct super_block *sb;
338
309
struct dentry *parent, *src_parent = NULL, *h_parent;
339
310
struct inode *dir, *src_dir = NULL;
340
struct aufs_sbinfo *sbinfo;
311
struct au_sbinfo *sbinfo;
341
312
const int add_entry = au_ftest_wrdir(args->flags, ADD_ENTRY);
342
313
const int lock_srcdir = au_ftest_wrdir(args->flags, LOCK_SRCDIR);
418
389
err = au_lkup_neg(dentry, bcpup);
420
391
vfsub_i_unlock(h_parent->d_inode);
421
if (bstart < bcpup && dbstart(dentry) < 0) {
422
set_dbstart(dentry, 0);
392
if (bstart < bcpup && au_dbstart(dentry) < 0) {
393
au_set_dbstart(dentry, 0);
423
394
au_update_dbrange(dentry, /*do_put_zero*/0);
448
419
vfsub_i_lock_nested(h_inode, AuLsc_I_CHILD);
450
hdir2_lock(h_inode, inode, bindex);
421
au_hdir2_lock(h_inode, inode, bindex);
453
424
static void au_hi_unlock(struct inode *h_inode, int isdir, struct inode *inode,
457
428
vfsub_i_unlock(h_inode);
459
hdir_unlock(h_inode, inode, bindex);
430
au_hdir_unlock(h_inode, inode, bindex);
462
433
struct au_icpup_args {
463
434
aufs_bindex_t btgt;
464
435
unsigned char isdir, did_cpup; /* flags */
436
unsigned char hinotify;
466
437
struct dentry *parent, *gparent, *h_dentry;
467
438
struct inode *dir, *gdir, *h_inode, *h_dir;
525
496
rargs->h_dir = au_h_iptr_i(rargs->dir, rargs->btgt);
526
hdir_lock(rargs->h_dir, rargs->dir, rargs->btgt);
497
au_hdir_lock(rargs->h_dir, rargs->dir, rargs->btgt);
527
498
au_hi_lock(rargs->h_inode, rargs->isdir, inode, bstart);
528
499
if (!d_unhashed(dentry)) {
529
500
err = au_sio_cpup_simple(dentry, rargs->btgt, sz, AuCpup_DTIME);
552
523
AuDebugOn(!rargs->h_inode);
554
525
au_hi_lock(rargs->h_inode, rargs->isdir, inode, rargs->btgt);
555
hdir_unlock(rargs->h_dir, rargs->dir, rargs->btgt);
526
au_hdir_unlock(rargs->h_dir, rargs->dir, rargs->btgt);
557
528
goto out; /* success */
582
553
struct dentry *dentry;
583
554
struct au_icpup_args rargs;
585
LKTRTrace("i%lu, 0x%x, %lld, %lld\n",
586
inode->i_ino, mode, offset, len);
556
LKTRTrace("i%lu, 0x%x, %lld, %lld\n", inode->i_ino, mode, offset, len);
588
558
sb = inode->i_sb;
589
559
si_read_lock(sb, AuLock_FLUSH);
668
638
if (unlikely(err < 0))
672
di_write_lock_child(dentry);
673
bstart = dbstart(dentry);
674
if (S_ISDIR(dentry->d_inode->i_mode))
675
au_fset_wrdir(wr_dir_args.flags, ISDIR);
676
err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
679
if (unlikely(err < 0))
682
/* crazy udba locks */
683
udba = au_flag_test_udba_inotify(sb);
686
if (!IS_ROOT(dentry)) {
687
parent = dget_parent(dentry);
688
dir = parent->d_inode;
689
di_read_lock_parent(parent, AuLock_IR);
691
//todo: meaningless lock if CONFIG_AUFS_DEBUG is disabled.
694
if (unlikely(udba && parent && !IS_ROOT(parent))) {
695
gparent = dget_parent(parent);
696
gdir = gparent->d_inode;
697
ii_read_lock_parent2(gdir);
700
h_dentry = au_h_dptr(dentry);
701
h_inode = h_dentry->d_inode;
704
#define HiLock(bindex) \
706
if (!au_ftest_wrdir(wr_dir_args.flags, ISDIR)) \
707
vfsub_i_lock_nested(h_inode, AuLsc_I_CHILD); \
709
hdir2_lock(h_inode, inode, bindex); \
711
#define HiUnlock(bindex) \
713
if (!au_ftest_wrdir(wr_dir_args.flags, ISDIR)) \
714
vfsub_i_unlock(h_inode); \
716
hdir_unlock(h_inode, inode, bindex); \
719
if (bstart != bcpup) {
722
/* do not drop ATTR_SIZE here, to call vmtruncate() */
723
if ((ia->ia_valid & ATTR_SIZE)
724
&& ia->ia_size < i_size_read(inode))
727
h_dir = au_h_iptr_i(dir, bcpup);
728
hdir_lock(h_dir, dir, bcpup);
730
if (!d_unhashed(dentry))
731
err = au_sio_cpup_simple(dentry, bcpup, size,
734
hi_wh = au_hi_wh(inode, bcpup);
736
err = au_sio_cpup_wh(dentry, bcpup, size,
739
hi_wh = au_hi_wh(inode, bcpup);
748
hdir_unlock(h_dir, dir, bcpup);
753
h_dentry = au_h_dptr(dentry);
755
h_dentry = hi_wh; /* do not dget here */
756
h_inode = h_dentry->d_inode;
758
ia->ia_valid &= ~ATTR_FILE;
762
641
if ((ia->ia_valid & ATTR_SIZE)
763
642
&& ia->ia_size < i_size_read(inode)) {
764
643
err = vmtruncate(inode, ia->ia_size);
775
vfsub_args_init(&vargs, &ign, au_need_dlgt(sb), 0);
776
if (unlikely(rargs.udba && rargs.dir)) {
654
vfsub_args_init(&vargs, &ign, au_opt_test_dlgt(au_mntflags(sb)), 0);
655
if (unlikely(rargs.hinotify && rargs.dir)) {
777
656
events = vfsub_events_notify_change(ia);
779
658
vfsub_ign_hinode(&vargs, events,
780
itohi(rargs.dir, rargs.btgt));
659
au_hi(rargs.dir, rargs.btgt));
782
661
err = vfsub_notify_change(rargs.h_dentry, ia, &vargs);
809
/* currently, for fuse only */
810
#ifdef CONFIG_AUFS_WORKAROUND_FUSE
811
static int aufs_getattr(struct vfsmount *mnt, struct dentry *dentry,
815
struct inode *inode, *h_inode;
816
struct dentry *h_dentry;
818
LKTRTrace("%.*s\n", AuDLNPair(dentry));
821
aufs_read_lock(dentry, AuLock_IR);
822
inode = dentry->d_inode;
823
h_inode = au_h_iptr(inode);
824
if (unlikely(au_test_fuse(h_inode->i_sb))) {
825
h_dentry = d_find_alias(h_inode);
826
/* simply gave up updating fuse inode */
829
if (!au_update_fuse_h_inode(NULL, h_dentry))
830
au_cpup_attr_all(inode);
834
generic_fillattr(inode, st);
836
aufs_read_unlock(dentry, AuLock_IR);
839
#endif /* CONFIG_AUFS_WORKAROUND_FUSE */
841
688
/* ---------------------------------------------------------------------- */
843
690
static int h_readlink(struct dentry *dentry, int bindex, char __user *buf,
856
703
sb = dentry->d_sb;
857
704
if (!au_test_ro(sb, bindex, dentry->d_inode)) {
858
touch_atime(sbr_mnt(sb, bindex), h_dentry);
705
touch_atime(au_sbr_mnt(sb, bindex), h_dentry);
859
706
au_update_fuse_h_inode(NULL, h_dentry); /*ignore*/
860
707
dentry->d_inode->i_atime = h_dentry->d_inode->i_atime;
869
716
LKTRTrace("%.*s, %d\n", AuDLNPair(dentry), bufsiz);
871
718
aufs_read_lock(dentry, AuLock_IR);
872
err = h_readlink(dentry, dbstart(dentry), buf, bufsiz);
719
err = h_readlink(dentry, au_dbstart(dentry), buf, bufsiz);
874
721
aufs_read_unlock(dentry, AuLock_IR);
893
740
aufs_read_lock(dentry, AuLock_IR);
894
741
old_fs = get_fs();
895
742
set_fs(KERNEL_DS);
896
err = h_readlink(dentry, dbstart(dentry), (char __user *)buf, PATH_MAX);
743
err = h_readlink(dentry, au_dbstart(dentry), (char __user *)buf,
899
747
aufs_read_unlock(dentry, AuLock_IR);