aboutsummaryrefslogtreecommitdiffstats
path: root/fs/gfs2/ops_inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/gfs2/ops_inode.c')
-rw-r--r--fs/gfs2/ops_inode.c134
1 files changed, 60 insertions, 74 deletions
diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c
index ef6e5ed70e94..636dda4c7d38 100644
--- a/fs/gfs2/ops_inode.c
+++ b/fs/gfs2/ops_inode.c
@@ -59,7 +59,7 @@ static int gfs2_create(struct inode *dir, struct dentry *dentry,
59 gfs2_holder_init(dip->i_gl, 0, 0, ghs); 59 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
60 60
61 for (;;) { 61 for (;;) {
62 inode = gfs2_createi(ghs, &dentry->d_name, S_IFREG | mode); 62 inode = gfs2_createi(ghs, &dentry->d_name, S_IFREG | mode, 0);
63 if (!IS_ERR(inode)) { 63 if (!IS_ERR(inode)) {
64 gfs2_trans_end(sdp); 64 gfs2_trans_end(sdp);
65 if (dip->i_alloc.al_rgd) 65 if (dip->i_alloc.al_rgd)
@@ -144,7 +144,7 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
144 int alloc_required; 144 int alloc_required;
145 int error; 145 int error;
146 146
147 if (S_ISDIR(ip->i_di.di_mode)) 147 if (S_ISDIR(inode->i_mode))
148 return -EPERM; 148 return -EPERM;
149 149
150 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs); 150 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
@@ -169,7 +169,7 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
169 } 169 }
170 170
171 error = -EINVAL; 171 error = -EINVAL;
172 if (!dip->i_di.di_nlink) 172 if (!dip->i_inode.i_nlink)
173 goto out_gunlock; 173 goto out_gunlock;
174 error = -EFBIG; 174 error = -EFBIG;
175 if (dip->i_di.di_entries == (u32)-1) 175 if (dip->i_di.di_entries == (u32)-1)
@@ -178,10 +178,10 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
178 if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) 178 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
179 goto out_gunlock; 179 goto out_gunlock;
180 error = -EINVAL; 180 error = -EINVAL;
181 if (!ip->i_di.di_nlink) 181 if (!ip->i_inode.i_nlink)
182 goto out_gunlock; 182 goto out_gunlock;
183 error = -EMLINK; 183 error = -EMLINK;
184 if (ip->i_di.di_nlink == (u32)-1) 184 if (ip->i_inode.i_nlink == (u32)-1)
185 goto out_gunlock; 185 goto out_gunlock;
186 186
187 alloc_required = error = gfs2_diradd_alloc_required(dir, &dentry->d_name); 187 alloc_required = error = gfs2_diradd_alloc_required(dir, &dentry->d_name);
@@ -196,8 +196,7 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
196 if (error) 196 if (error)
197 goto out_alloc; 197 goto out_alloc;
198 198
199 error = gfs2_quota_check(dip, dip->i_di.di_uid, 199 error = gfs2_quota_check(dip, dip->i_inode.i_uid, dip->i_inode.i_gid);
200 dip->i_di.di_gid);
201 if (error) 200 if (error)
202 goto out_gunlock_q; 201 goto out_gunlock_q;
203 202
@@ -220,7 +219,7 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
220 } 219 }
221 220
222 error = gfs2_dir_add(dir, &dentry->d_name, &ip->i_num, 221 error = gfs2_dir_add(dir, &dentry->d_name, &ip->i_num,
223 IF2DT(ip->i_di.di_mode)); 222 IF2DT(inode->i_mode));
224 if (error) 223 if (error)
225 goto out_end_trans; 224 goto out_end_trans;
226 225
@@ -326,7 +325,7 @@ static int gfs2_symlink(struct inode *dir, struct dentry *dentry,
326 325
327 gfs2_holder_init(dip->i_gl, 0, 0, ghs); 326 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
328 327
329 inode = gfs2_createi(ghs, &dentry->d_name, S_IFLNK | S_IRWXUGO); 328 inode = gfs2_createi(ghs, &dentry->d_name, S_IFLNK | S_IRWXUGO, 0);
330 if (IS_ERR(inode)) { 329 if (IS_ERR(inode)) {
331 gfs2_holder_uninit(ghs); 330 gfs2_holder_uninit(ghs);
332 return PTR_ERR(inode); 331 return PTR_ERR(inode);
@@ -339,7 +338,7 @@ static int gfs2_symlink(struct inode *dir, struct dentry *dentry,
339 error = gfs2_meta_inode_buffer(ip, &dibh); 338 error = gfs2_meta_inode_buffer(ip, &dibh);
340 339
341 if (!gfs2_assert_withdraw(sdp, !error)) { 340 if (!gfs2_assert_withdraw(sdp, !error)) {
342 gfs2_dinode_out(&ip->i_di, dibh->b_data); 341 gfs2_dinode_out(ip, dibh->b_data);
343 memcpy(dibh->b_data + sizeof(struct gfs2_dinode), symname, 342 memcpy(dibh->b_data + sizeof(struct gfs2_dinode), symname,
344 size); 343 size);
345 brelse(dibh); 344 brelse(dibh);
@@ -379,7 +378,7 @@ static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode)
379 378
380 gfs2_holder_init(dip->i_gl, 0, 0, ghs); 379 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
381 380
382 inode = gfs2_createi(ghs, &dentry->d_name, S_IFDIR | mode); 381 inode = gfs2_createi(ghs, &dentry->d_name, S_IFDIR | mode, 0);
383 if (IS_ERR(inode)) { 382 if (IS_ERR(inode)) {
384 gfs2_holder_uninit(ghs); 383 gfs2_holder_uninit(ghs);
385 return PTR_ERR(inode); 384 return PTR_ERR(inode);
@@ -387,10 +386,9 @@ static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode)
387 386
388 ip = ghs[1].gh_gl->gl_object; 387 ip = ghs[1].gh_gl->gl_object;
389 388
390 ip->i_di.di_nlink = 2; 389 ip->i_inode.i_nlink = 2;
391 ip->i_di.di_size = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode); 390 ip->i_di.di_size = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode);
392 ip->i_di.di_flags |= GFS2_DIF_JDATA; 391 ip->i_di.di_flags |= GFS2_DIF_JDATA;
393 ip->i_di.di_payload_format = GFS2_FORMAT_DE;
394 ip->i_di.di_entries = 2; 392 ip->i_di.di_entries = 2;
395 393
396 error = gfs2_meta_inode_buffer(ip, &dibh); 394 error = gfs2_meta_inode_buffer(ip, &dibh);
@@ -414,7 +412,7 @@ static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode)
414 gfs2_inum_out(&dip->i_num, &dent->de_inum); 412 gfs2_inum_out(&dip->i_num, &dent->de_inum);
415 dent->de_type = cpu_to_be16(DT_DIR); 413 dent->de_type = cpu_to_be16(DT_DIR);
416 414
417 gfs2_dinode_out(&ip->i_di, di); 415 gfs2_dinode_out(ip, di);
418 416
419 brelse(dibh); 417 brelse(dibh);
420 } 418 }
@@ -467,7 +465,7 @@ static int gfs2_rmdir(struct inode *dir, struct dentry *dentry)
467 465
468 if (ip->i_di.di_entries < 2) { 466 if (ip->i_di.di_entries < 2) {
469 if (gfs2_consist_inode(ip)) 467 if (gfs2_consist_inode(ip))
470 gfs2_dinode_print(&ip->i_di); 468 gfs2_dinode_print(ip);
471 error = -EIO; 469 error = -EIO;
472 goto out_gunlock; 470 goto out_gunlock;
473 } 471 }
@@ -504,47 +502,19 @@ out:
504static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode, 502static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode,
505 dev_t dev) 503 dev_t dev)
506{ 504{
507 struct gfs2_inode *dip = GFS2_I(dir), *ip; 505 struct gfs2_inode *dip = GFS2_I(dir);
508 struct gfs2_sbd *sdp = GFS2_SB(dir); 506 struct gfs2_sbd *sdp = GFS2_SB(dir);
509 struct gfs2_holder ghs[2]; 507 struct gfs2_holder ghs[2];
510 struct inode *inode; 508 struct inode *inode;
511 struct buffer_head *dibh;
512 u32 major = 0, minor = 0;
513 int error;
514
515 switch (mode & S_IFMT) {
516 case S_IFBLK:
517 case S_IFCHR:
518 major = MAJOR(dev);
519 minor = MINOR(dev);
520 break;
521 case S_IFIFO:
522 case S_IFSOCK:
523 break;
524 default:
525 return -EOPNOTSUPP;
526 };
527 509
528 gfs2_holder_init(dip->i_gl, 0, 0, ghs); 510 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
529 511
530 inode = gfs2_createi(ghs, &dentry->d_name, mode); 512 inode = gfs2_createi(ghs, &dentry->d_name, mode, dev);
531 if (IS_ERR(inode)) { 513 if (IS_ERR(inode)) {
532 gfs2_holder_uninit(ghs); 514 gfs2_holder_uninit(ghs);
533 return PTR_ERR(inode); 515 return PTR_ERR(inode);
534 } 516 }
535 517
536 ip = ghs[1].gh_gl->gl_object;
537
538 ip->i_di.di_major = major;
539 ip->i_di.di_minor = minor;
540
541 error = gfs2_meta_inode_buffer(ip, &dibh);
542
543 if (!gfs2_assert_withdraw(sdp, !error)) {
544 gfs2_dinode_out(&ip->i_di, dibh->b_data);
545 brelse(dibh);
546 }
547
548 gfs2_trans_end(sdp); 518 gfs2_trans_end(sdp);
549 if (dip->i_alloc.al_rgd) 519 if (dip->i_alloc.al_rgd)
550 gfs2_inplace_release(dip); 520 gfs2_inplace_release(dip);
@@ -592,11 +562,10 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
592 562
593 /* Make sure we aren't trying to move a dirctory into it's subdir */ 563 /* Make sure we aren't trying to move a dirctory into it's subdir */
594 564
595 if (S_ISDIR(ip->i_di.di_mode) && odip != ndip) { 565 if (S_ISDIR(ip->i_inode.i_mode) && odip != ndip) {
596 dir_rename = 1; 566 dir_rename = 1;
597 567
598 error = gfs2_glock_nq_init(sdp->sd_rename_gl, 568 error = gfs2_glock_nq_init(sdp->sd_rename_gl, LM_ST_EXCLUSIVE, 0,
599 LM_ST_EXCLUSIVE, 0,
600 &r_gh); 569 &r_gh);
601 if (error) 570 if (error)
602 goto out; 571 goto out;
@@ -637,10 +606,10 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
637 if (error) 606 if (error)
638 goto out_gunlock; 607 goto out_gunlock;
639 608
640 if (S_ISDIR(nip->i_di.di_mode)) { 609 if (S_ISDIR(nip->i_inode.i_mode)) {
641 if (nip->i_di.di_entries < 2) { 610 if (nip->i_di.di_entries < 2) {
642 if (gfs2_consist_inode(nip)) 611 if (gfs2_consist_inode(nip))
643 gfs2_dinode_print(&nip->i_di); 612 gfs2_dinode_print(nip);
644 error = -EIO; 613 error = -EIO;
645 goto out_gunlock; 614 goto out_gunlock;
646 } 615 }
@@ -666,7 +635,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
666 }; 635 };
667 636
668 if (odip != ndip) { 637 if (odip != ndip) {
669 if (!ndip->i_di.di_nlink) { 638 if (!ndip->i_inode.i_nlink) {
670 error = -EINVAL; 639 error = -EINVAL;
671 goto out_gunlock; 640 goto out_gunlock;
672 } 641 }
@@ -674,8 +643,8 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
674 error = -EFBIG; 643 error = -EFBIG;
675 goto out_gunlock; 644 goto out_gunlock;
676 } 645 }
677 if (S_ISDIR(ip->i_di.di_mode) && 646 if (S_ISDIR(ip->i_inode.i_mode) &&
678 ndip->i_di.di_nlink == (u32)-1) { 647 ndip->i_inode.i_nlink == (u32)-1) {
679 error = -EMLINK; 648 error = -EMLINK;
680 goto out_gunlock; 649 goto out_gunlock;
681 } 650 }
@@ -702,8 +671,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
702 if (error) 671 if (error)
703 goto out_alloc; 672 goto out_alloc;
704 673
705 error = gfs2_quota_check(ndip, ndip->i_di.di_uid, 674 error = gfs2_quota_check(ndip, ndip->i_inode.i_uid, ndip->i_inode.i_gid);
706 ndip->i_di.di_gid);
707 if (error) 675 if (error)
708 goto out_gunlock_q; 676 goto out_gunlock_q;
709 677
@@ -729,7 +697,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
729 /* Remove the target file, if it exists */ 697 /* Remove the target file, if it exists */
730 698
731 if (nip) { 699 if (nip) {
732 if (S_ISDIR(nip->i_di.di_mode)) 700 if (S_ISDIR(nip->i_inode.i_mode))
733 error = gfs2_rmdiri(ndip, &ndentry->d_name, nip); 701 error = gfs2_rmdiri(ndip, &ndentry->d_name, nip);
734 else { 702 else {
735 error = gfs2_dir_del(ndip, &ndentry->d_name); 703 error = gfs2_dir_del(ndip, &ndentry->d_name);
@@ -760,9 +728,9 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
760 error = gfs2_meta_inode_buffer(ip, &dibh); 728 error = gfs2_meta_inode_buffer(ip, &dibh);
761 if (error) 729 if (error)
762 goto out_end_trans; 730 goto out_end_trans;
763 ip->i_di.di_ctime = get_seconds(); 731 ip->i_inode.i_ctime.tv_sec = get_seconds();
764 gfs2_trans_add_bh(ip->i_gl, dibh, 1); 732 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
765 gfs2_dinode_out(&ip->i_di, dibh->b_data); 733 gfs2_dinode_out(ip, dibh->b_data);
766 brelse(dibh); 734 brelse(dibh);
767 } 735 }
768 736
@@ -771,7 +739,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
771 goto out_end_trans; 739 goto out_end_trans;
772 740
773 error = gfs2_dir_add(ndir, &ndentry->d_name, &ip->i_num, 741 error = gfs2_dir_add(ndir, &ndentry->d_name, &ip->i_num,
774 IF2DT(ip->i_di.di_mode)); 742 IF2DT(ip->i_inode.i_mode));
775 if (error) 743 if (error)
776 goto out_end_trans; 744 goto out_end_trans;
777 745
@@ -867,6 +835,10 @@ static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd)
867 * @mask: 835 * @mask:
868 * @nd: passed from Linux VFS, ignored by us 836 * @nd: passed from Linux VFS, ignored by us
869 * 837 *
838 * This may be called from the VFS directly, or from within GFS2 with the
839 * inode locked, so we look to see if the glock is already locked and only
840 * lock the glock if its not already been done.
841 *
870 * Returns: errno 842 * Returns: errno
871 */ 843 */
872 844
@@ -875,15 +847,18 @@ static int gfs2_permission(struct inode *inode, int mask, struct nameidata *nd)
875 struct gfs2_inode *ip = GFS2_I(inode); 847 struct gfs2_inode *ip = GFS2_I(inode);
876 struct gfs2_holder i_gh; 848 struct gfs2_holder i_gh;
877 int error; 849 int error;
850 int unlock = 0;
878 851
879 if (ip->i_vn == ip->i_gl->gl_vn) 852 if (gfs2_glock_is_locked_by_me(ip->i_gl) == 0) {
880 return generic_permission(inode, mask, gfs2_check_acl); 853 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh);
854 if (error)
855 return error;
856 unlock = 1;
857 }
881 858
882 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh); 859 error = generic_permission(inode, mask, gfs2_check_acl);
883 if (!error) { 860 if (unlock)
884 error = generic_permission(inode, mask, gfs2_check_acl_locked);
885 gfs2_glock_dq_uninit(&i_gh); 861 gfs2_glock_dq_uninit(&i_gh);
886 }
887 862
888 return error; 863 return error;
889} 864}
@@ -914,8 +889,8 @@ static int setattr_chown(struct inode *inode, struct iattr *attr)
914 u32 ouid, ogid, nuid, ngid; 889 u32 ouid, ogid, nuid, ngid;
915 int error; 890 int error;
916 891
917 ouid = ip->i_di.di_uid; 892 ouid = inode->i_uid;
918 ogid = ip->i_di.di_gid; 893 ogid = inode->i_gid;
919 nuid = attr->ia_uid; 894 nuid = attr->ia_uid;
920 ngid = attr->ia_gid; 895 ngid = attr->ia_gid;
921 896
@@ -946,10 +921,9 @@ static int setattr_chown(struct inode *inode, struct iattr *attr)
946 921
947 error = inode_setattr(inode, attr); 922 error = inode_setattr(inode, attr);
948 gfs2_assert_warn(sdp, !error); 923 gfs2_assert_warn(sdp, !error);
949 gfs2_inode_attr_out(ip);
950 924
951 gfs2_trans_add_bh(ip->i_gl, dibh, 1); 925 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
952 gfs2_dinode_out(&ip->i_di, dibh->b_data); 926 gfs2_dinode_out(ip, dibh->b_data);
953 brelse(dibh); 927 brelse(dibh);
954 928
955 if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) { 929 if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) {
@@ -1018,6 +992,12 @@ out:
1018 * @dentry: The dentry to stat 992 * @dentry: The dentry to stat
1019 * @stat: The inode's stats 993 * @stat: The inode's stats
1020 * 994 *
995 * This may be called from the VFS directly, or from within GFS2 with the
996 * inode locked, so we look to see if the glock is already locked and only
997 * lock the glock if its not already been done. Note that its the NFS
998 * readdirplus operation which causes this to be called (from filldir)
999 * with the glock already held.
1000 *
1021 * Returns: errno 1001 * Returns: errno
1022 */ 1002 */
1023 1003
@@ -1028,14 +1008,20 @@ static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry,
1028 struct gfs2_inode *ip = GFS2_I(inode); 1008 struct gfs2_inode *ip = GFS2_I(inode);
1029 struct gfs2_holder gh; 1009 struct gfs2_holder gh;
1030 int error; 1010 int error;
1011 int unlock = 0;
1031 1012
1032 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh); 1013 if (gfs2_glock_is_locked_by_me(ip->i_gl) == 0) {
1033 if (!error) { 1014 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
1034 generic_fillattr(inode, stat); 1015 if (error)
1035 gfs2_glock_dq_uninit(&gh); 1016 return error;
1017 unlock = 1;
1036 } 1018 }
1037 1019
1038 return error; 1020 generic_fillattr(inode, stat);
1021 if (unlock);
1022 gfs2_glock_dq_uninit(&gh);
1023
1024 return 0;
1039} 1025}
1040 1026
1041static int gfs2_setxattr(struct dentry *dentry, const char *name, 1027static int gfs2_setxattr(struct dentry *dentry, const char *name,