2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
10 #include <linux/slab.h>
11 #include <linux/spinlock.h>
12 #include <linux/completion.h>
13 #include <linux/buffer_head.h>
14 #include <linux/namei.h>
15 #include <linux/utsname.h>
17 #include <linux/xattr.h>
18 #include <linux/posix_acl.h>
19 #include <linux/gfs2_ondisk.h>
20 #include <linux/crc32.h>
21 #include <linux/lm_interface.h>
22 #include <asm/uaccess.h>
34 #include "ops_dentry.h"
35 #include "ops_inode.h"
42 * gfs2_create - Create a file
43 * @dir: The directory in which to create the file
44 * @dentry: The dentry of the new file
45 * @mode: The mode of the new file
50 static int gfs2_create(struct inode *dir, struct dentry *dentry,
51 int mode, struct nameidata *nd)
53 struct gfs2_inode *dip = GFS2_I(dir);
54 struct gfs2_sbd *sdp = GFS2_SB(dir);
55 struct gfs2_holder ghs[2];
58 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
61 inode = gfs2_createi(ghs, &dentry->d_name, S_IFREG | mode, 0);
64 if (dip->i_alloc.al_rgd)
65 gfs2_inplace_release(dip);
66 gfs2_quota_unlock(dip);
68 gfs2_glock_dq_uninit_m(2, ghs);
69 mark_inode_dirty(inode);
71 } else if (PTR_ERR(inode) != -EEXIST ||
72 (nd->intent.open.flags & O_EXCL)) {
73 gfs2_holder_uninit(ghs);
74 return PTR_ERR(inode);
77 inode = gfs2_lookupi(dir, &dentry->d_name, 0, nd);
80 gfs2_holder_uninit(ghs);
83 gfs2_holder_uninit(ghs);
84 return PTR_ERR(inode);
89 d_instantiate(dentry, inode);
95 * gfs2_lookup - Look up a filename in a directory and return its inode
96 * @dir: The directory inode
97 * @dentry: The dentry of the new inode
98 * @nd: passed from Linux VFS, ignored by us
100 * Called by the VFS layer. Lock dir and call gfs2_lookupi()
105 static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry,
106 struct nameidata *nd)
108 struct inode *inode = NULL;
110 dentry->d_op = &gfs2_dops;
112 inode = gfs2_lookupi(dir, &dentry->d_name, 0, nd);
113 if (inode && IS_ERR(inode))
114 return ERR_PTR(PTR_ERR(inode));
117 return d_splice_alias(inode, dentry);
118 d_add(dentry, inode);
124 * gfs2_link - Link to a file
125 * @old_dentry: The inode to link
126 * @dir: Add link to this directory
127 * @dentry: The name of the link
129 * Link the inode in "old_dentry" into the directory "dir" with the
135 static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
136 struct dentry *dentry)
138 struct gfs2_inode *dip = GFS2_I(dir);
139 struct gfs2_sbd *sdp = GFS2_SB(dir);
140 struct inode *inode = old_dentry->d_inode;
141 struct gfs2_inode *ip = GFS2_I(inode);
142 struct gfs2_holder ghs[2];
146 if (S_ISDIR(inode->i_mode))
149 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
150 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
152 error = gfs2_glock_nq_m(2, ghs);
156 error = permission(dir, MAY_WRITE | MAY_EXEC, NULL);
160 error = gfs2_dir_search(dir, &dentry->d_name, NULL, NULL);
171 if (!dip->i_inode.i_nlink)
174 if (dip->i_di.di_entries == (u32)-1)
177 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
180 if (!ip->i_inode.i_nlink)
183 if (ip->i_inode.i_nlink == (u32)-1)
186 alloc_required = error = gfs2_diradd_alloc_required(dir, &dentry->d_name);
191 if (alloc_required) {
192 struct gfs2_alloc *al = gfs2_alloc_get(dip);
194 error = gfs2_quota_lock(dip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
198 error = gfs2_quota_check(dip, dip->i_inode.i_uid, dip->i_inode.i_gid);
202 al->al_requested = sdp->sd_max_dirres;
204 error = gfs2_inplace_reserve(dip);
208 error = gfs2_trans_begin(sdp, sdp->sd_max_dirres +
209 al->al_rgd->rd_ri.ri_length +
210 2 * RES_DINODE + RES_STATFS +
215 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + RES_LEAF, 0);
220 error = gfs2_dir_add(dir, &dentry->d_name, &ip->i_num,
221 IF2DT(inode->i_mode));
225 error = gfs2_change_nlink(ip, +1);
231 gfs2_inplace_release(dip);
234 gfs2_quota_unlock(dip);
239 gfs2_glock_dq_m(2, ghs);
241 gfs2_holder_uninit(ghs);
242 gfs2_holder_uninit(ghs + 1);
244 atomic_inc(&inode->i_count);
245 d_instantiate(dentry, inode);
246 mark_inode_dirty(inode);
252 * gfs2_unlink - Unlink a file
253 * @dir: The inode of the directory containing the file to unlink
254 * @dentry: The file itself
256 * Unlink a file. Call gfs2_unlinki()
261 static int gfs2_unlink(struct inode *dir, struct dentry *dentry)
263 struct gfs2_inode *dip = GFS2_I(dir);
264 struct gfs2_sbd *sdp = GFS2_SB(dir);
265 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
266 struct gfs2_holder ghs[3];
267 struct gfs2_rgrpd *rgd;
268 struct gfs2_holder ri_gh;
271 error = gfs2_rindex_hold(sdp, &ri_gh);
275 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
276 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
278 rgd = gfs2_blk2rgrpd(sdp, ip->i_num.no_addr);
279 gfs2_holder_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + 2);
282 error = gfs2_glock_nq_m(3, ghs);
286 error = gfs2_unlink_ok(dip, &dentry->d_name, ip);
290 error = gfs2_trans_begin(sdp, 2*RES_DINODE + RES_LEAF + RES_RG_BIT, 0);
294 error = gfs2_dir_del(dip, &dentry->d_name);
298 error = gfs2_change_nlink(ip, -1);
303 gfs2_glock_dq_m(3, ghs);
305 gfs2_holder_uninit(ghs);
306 gfs2_holder_uninit(ghs + 1);
307 gfs2_holder_uninit(ghs + 2);
308 gfs2_glock_dq_uninit(&ri_gh);
313 * gfs2_symlink - Create a symlink
314 * @dir: The directory to create the symlink in
315 * @dentry: The dentry to put the symlink in
316 * @symname: The thing which the link points to
321 static int gfs2_symlink(struct inode *dir, struct dentry *dentry,
324 struct gfs2_inode *dip = GFS2_I(dir), *ip;
325 struct gfs2_sbd *sdp = GFS2_SB(dir);
326 struct gfs2_holder ghs[2];
328 struct buffer_head *dibh;
332 /* Must be stuffed with a null terminator for gfs2_follow_link() */
333 size = strlen(symname);
334 if (size > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode) - 1)
335 return -ENAMETOOLONG;
337 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
339 inode = gfs2_createi(ghs, &dentry->d_name, S_IFLNK | S_IRWXUGO, 0);
341 gfs2_holder_uninit(ghs);
342 return PTR_ERR(inode);
345 ip = ghs[1].gh_gl->gl_object;
347 ip->i_di.di_size = size;
349 error = gfs2_meta_inode_buffer(ip, &dibh);
351 if (!gfs2_assert_withdraw(sdp, !error)) {
352 gfs2_dinode_out(ip, dibh->b_data);
353 memcpy(dibh->b_data + sizeof(struct gfs2_dinode), symname,
359 if (dip->i_alloc.al_rgd)
360 gfs2_inplace_release(dip);
361 gfs2_quota_unlock(dip);
364 gfs2_glock_dq_uninit_m(2, ghs);
366 d_instantiate(dentry, inode);
367 mark_inode_dirty(inode);
373 * gfs2_mkdir - Make a directory
374 * @dir: The parent directory of the new one
375 * @dentry: The dentry of the new directory
376 * @mode: The mode of the new directory
381 static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode)
383 struct gfs2_inode *dip = GFS2_I(dir), *ip;
384 struct gfs2_sbd *sdp = GFS2_SB(dir);
385 struct gfs2_holder ghs[2];
387 struct buffer_head *dibh;
390 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
392 inode = gfs2_createi(ghs, &dentry->d_name, S_IFDIR | mode, 0);
394 gfs2_holder_uninit(ghs);
395 return PTR_ERR(inode);
398 ip = ghs[1].gh_gl->gl_object;
400 ip->i_inode.i_nlink = 2;
401 ip->i_di.di_size = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode);
402 ip->i_di.di_flags |= GFS2_DIF_JDATA;
403 ip->i_di.di_entries = 2;
405 error = gfs2_meta_inode_buffer(ip, &dibh);
407 if (!gfs2_assert_withdraw(sdp, !error)) {
408 struct gfs2_dinode *di = (struct gfs2_dinode *)dibh->b_data;
409 struct gfs2_dirent *dent = (struct gfs2_dirent *)(di+1);
412 gfs2_str2qstr(&str, ".");
413 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
414 gfs2_qstr2dirent(&str, GFS2_DIRENT_SIZE(str.len), dent);
415 dent->de_inum = di->di_num; /* already GFS2 endian */
416 dent->de_type = cpu_to_be16(DT_DIR);
417 di->di_entries = cpu_to_be32(1);
419 gfs2_str2qstr(&str, "..");
420 dent = (struct gfs2_dirent *)((char*)dent + GFS2_DIRENT_SIZE(1));
421 gfs2_qstr2dirent(&str, dibh->b_size - GFS2_DIRENT_SIZE(1) - sizeof(struct gfs2_dinode), dent);
423 gfs2_inum_out(&dip->i_num, &dent->de_inum);
424 dent->de_type = cpu_to_be16(DT_DIR);
426 gfs2_dinode_out(ip, di);
431 error = gfs2_change_nlink(dip, +1);
432 gfs2_assert_withdraw(sdp, !error); /* dip already pinned */
435 if (dip->i_alloc.al_rgd)
436 gfs2_inplace_release(dip);
437 gfs2_quota_unlock(dip);
440 gfs2_glock_dq_uninit_m(2, ghs);
442 d_instantiate(dentry, inode);
443 mark_inode_dirty(inode);
449 * gfs2_rmdir - Remove a directory
450 * @dir: The parent directory of the directory to be removed
451 * @dentry: The dentry of the directory to remove
453 * Remove a directory. Call gfs2_rmdiri()
458 static int gfs2_rmdir(struct inode *dir, struct dentry *dentry)
460 struct gfs2_inode *dip = GFS2_I(dir);
461 struct gfs2_sbd *sdp = GFS2_SB(dir);
462 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
463 struct gfs2_holder ghs[3];
464 struct gfs2_rgrpd *rgd;
465 struct gfs2_holder ri_gh;
469 error = gfs2_rindex_hold(sdp, &ri_gh);
472 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
473 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
475 rgd = gfs2_blk2rgrpd(sdp, ip->i_num.no_addr);
476 gfs2_holder_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + 2);
478 error = gfs2_glock_nq_m(3, ghs);
482 error = gfs2_unlink_ok(dip, &dentry->d_name, ip);
486 if (ip->i_di.di_entries < 2) {
487 if (gfs2_consist_inode(ip))
488 gfs2_dinode_print(ip);
492 if (ip->i_di.di_entries > 2) {
497 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + 3 * RES_LEAF + RES_RG_BIT, 0);
501 error = gfs2_rmdiri(dip, &dentry->d_name, ip);
506 gfs2_glock_dq_m(3, ghs);
508 gfs2_holder_uninit(ghs);
509 gfs2_holder_uninit(ghs + 1);
510 gfs2_holder_uninit(ghs + 2);
511 gfs2_glock_dq_uninit(&ri_gh);
516 * gfs2_mknod - Make a special file
517 * @dir: The directory in which the special file will reside
518 * @dentry: The dentry of the special file
519 * @mode: The mode of the special file
520 * @rdev: The device specification of the special file
524 static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode,
527 struct gfs2_inode *dip = GFS2_I(dir);
528 struct gfs2_sbd *sdp = GFS2_SB(dir);
529 struct gfs2_holder ghs[2];
532 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
534 inode = gfs2_createi(ghs, &dentry->d_name, mode, dev);
536 gfs2_holder_uninit(ghs);
537 return PTR_ERR(inode);
541 if (dip->i_alloc.al_rgd)
542 gfs2_inplace_release(dip);
543 gfs2_quota_unlock(dip);
546 gfs2_glock_dq_uninit_m(2, ghs);
548 d_instantiate(dentry, inode);
549 mark_inode_dirty(inode);
555 * gfs2_rename - Rename a file
556 * @odir: Parent directory of old file name
557 * @odentry: The old dentry of the file
558 * @ndir: Parent directory of new file name
559 * @ndentry: The new dentry of the file
564 static int gfs2_rename(struct inode *odir, struct dentry *odentry,
565 struct inode *ndir, struct dentry *ndentry)
567 struct gfs2_inode *odip = GFS2_I(odir);
568 struct gfs2_inode *ndip = GFS2_I(ndir);
569 struct gfs2_inode *ip = GFS2_I(odentry->d_inode);
570 struct gfs2_inode *nip = NULL;
571 struct gfs2_sbd *sdp = GFS2_SB(odir);
572 struct gfs2_holder ghs[5], r_gh;
573 struct gfs2_rgrpd *nrgd;
580 if (ndentry->d_inode) {
581 nip = GFS2_I(ndentry->d_inode);
586 /* Make sure we aren't trying to move a dirctory into it's subdir */
588 if (S_ISDIR(ip->i_inode.i_mode) && odip != ndip) {
591 error = gfs2_glock_nq_init(sdp->sd_rename_gl, LM_ST_EXCLUSIVE, 0,
596 error = gfs2_ok_to_move(ip, ndip);
602 gfs2_holder_init(odip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
604 gfs2_holder_init(ndip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
607 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
611 gfs2_holder_init(nip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
613 /* grab the resource lock for unlink flag twiddling
614 * this is the case of the target file already existing
615 * so we unlink before doing the rename
617 nrgd = gfs2_blk2rgrpd(sdp, nip->i_num.no_addr);
619 gfs2_holder_init(nrgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh++);
622 error = gfs2_glock_nq_m(num_gh, ghs);
626 /* Check out the old directory */
628 error = gfs2_unlink_ok(odip, &odentry->d_name, ip);
632 /* Check out the new directory */
635 error = gfs2_unlink_ok(ndip, &ndentry->d_name, nip);
639 if (S_ISDIR(nip->i_inode.i_mode)) {
640 if (nip->i_di.di_entries < 2) {
641 if (gfs2_consist_inode(nip))
642 gfs2_dinode_print(nip);
646 if (nip->i_di.di_entries > 2) {
652 error = permission(ndir, MAY_WRITE | MAY_EXEC, NULL);
656 error = gfs2_dir_search(ndir, &ndentry->d_name, NULL, NULL);
668 if (!ndip->i_inode.i_nlink) {
672 if (ndip->i_di.di_entries == (u32)-1) {
676 if (S_ISDIR(ip->i_inode.i_mode) &&
677 ndip->i_inode.i_nlink == (u32)-1) {
684 /* Check out the dir to be renamed */
687 error = permission(odentry->d_inode, MAY_WRITE, NULL);
692 alloc_required = error = gfs2_diradd_alloc_required(ndir, &ndentry->d_name);
697 if (alloc_required) {
698 struct gfs2_alloc *al = gfs2_alloc_get(ndip);
700 error = gfs2_quota_lock(ndip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
704 error = gfs2_quota_check(ndip, ndip->i_inode.i_uid, ndip->i_inode.i_gid);
708 al->al_requested = sdp->sd_max_dirres;
710 error = gfs2_inplace_reserve(ndip);
714 error = gfs2_trans_begin(sdp, sdp->sd_max_dirres +
715 al->al_rgd->rd_ri.ri_length +
716 4 * RES_DINODE + 4 * RES_LEAF +
717 RES_STATFS + RES_QUOTA + 4, 0);
721 error = gfs2_trans_begin(sdp, 4 * RES_DINODE +
722 5 * RES_LEAF + 4, 0);
727 /* Remove the target file, if it exists */
730 if (S_ISDIR(nip->i_inode.i_mode))
731 error = gfs2_rmdiri(ndip, &ndentry->d_name, nip);
733 error = gfs2_dir_del(ndip, &ndentry->d_name);
736 error = gfs2_change_nlink(nip, -1);
744 gfs2_str2qstr(&name, "..");
746 error = gfs2_change_nlink(ndip, +1);
749 error = gfs2_change_nlink(odip, -1);
753 error = gfs2_dir_mvino(ip, &name, &ndip->i_num, DT_DIR);
757 struct buffer_head *dibh;
758 error = gfs2_meta_inode_buffer(ip, &dibh);
761 ip->i_inode.i_ctime = CURRENT_TIME_SEC;
762 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
763 gfs2_dinode_out(ip, dibh->b_data);
767 error = gfs2_dir_del(odip, &odentry->d_name);
771 error = gfs2_dir_add(ndir, &ndentry->d_name, &ip->i_num,
772 IF2DT(ip->i_inode.i_mode));
780 gfs2_inplace_release(ndip);
783 gfs2_quota_unlock(ndip);
786 gfs2_alloc_put(ndip);
788 gfs2_glock_dq_m(num_gh, ghs);
790 for (x = 0; x < num_gh; x++)
791 gfs2_holder_uninit(ghs + x);
794 gfs2_glock_dq_uninit(&r_gh);
800 * gfs2_readlink - Read the value of a symlink
801 * @dentry: the symlink
802 * @buf: the buffer to read the symlink data into
803 * @size: the size of the buffer
808 static int gfs2_readlink(struct dentry *dentry, char __user *user_buf,
811 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
812 char array[GFS2_FAST_NAME_SIZE], *buf = array;
813 unsigned int len = GFS2_FAST_NAME_SIZE;
816 error = gfs2_readlinki(ip, &buf, &len);
820 if (user_size > len - 1)
823 if (copy_to_user(user_buf, buf, user_size))
835 * gfs2_follow_link - Follow a symbolic link
836 * @dentry: The dentry of the link
837 * @nd: Data that we pass to vfs_follow_link()
839 * This can handle symlinks of any size. It is optimised for symlinks
840 * under GFS2_FAST_NAME_SIZE.
842 * Returns: 0 on success or error code
845 static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd)
847 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
848 char array[GFS2_FAST_NAME_SIZE], *buf = array;
849 unsigned int len = GFS2_FAST_NAME_SIZE;
852 error = gfs2_readlinki(ip, &buf, &len);
854 error = vfs_follow_link(nd, buf);
859 return ERR_PTR(error);
866 * @nd: passed from Linux VFS, ignored by us
868 * This may be called from the VFS directly, or from within GFS2 with the
869 * inode locked, so we look to see if the glock is already locked and only
870 * lock the glock if its not already been done.
875 static int gfs2_permission(struct inode *inode, int mask, struct nameidata *nd)
877 struct gfs2_inode *ip = GFS2_I(inode);
878 struct gfs2_holder i_gh;
882 if (gfs2_glock_is_locked_by_me(ip->i_gl) == 0) {
883 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh);
889 error = generic_permission(inode, mask, gfs2_check_acl);
891 gfs2_glock_dq_uninit(&i_gh);
896 static int setattr_size(struct inode *inode, struct iattr *attr)
898 struct gfs2_inode *ip = GFS2_I(inode);
901 if (attr->ia_size != ip->i_di.di_size) {
902 error = vmtruncate(inode, attr->ia_size);
907 error = gfs2_truncatei(ip, attr->ia_size);
914 static int setattr_chown(struct inode *inode, struct iattr *attr)
916 struct gfs2_inode *ip = GFS2_I(inode);
917 struct gfs2_sbd *sdp = GFS2_SB(inode);
918 struct buffer_head *dibh;
919 u32 ouid, ogid, nuid, ngid;
927 if (!(attr->ia_valid & ATTR_UID) || ouid == nuid)
928 ouid = nuid = NO_QUOTA_CHANGE;
929 if (!(attr->ia_valid & ATTR_GID) || ogid == ngid)
930 ogid = ngid = NO_QUOTA_CHANGE;
934 error = gfs2_quota_lock(ip, nuid, ngid);
938 if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) {
939 error = gfs2_quota_check(ip, nuid, ngid);
944 error = gfs2_trans_begin(sdp, RES_DINODE + 2 * RES_QUOTA, 0);
948 error = gfs2_meta_inode_buffer(ip, &dibh);
952 error = inode_setattr(inode, attr);
953 gfs2_assert_warn(sdp, !error);
955 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
956 gfs2_dinode_out(ip, dibh->b_data);
959 if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) {
960 gfs2_quota_change(ip, -ip->i_di.di_blocks, ouid, ogid);
961 gfs2_quota_change(ip, ip->i_di.di_blocks, nuid, ngid);
967 gfs2_quota_unlock(ip);
974 * gfs2_setattr - Change attributes on an inode
975 * @dentry: The dentry which is changing
976 * @attr: The structure describing the change
978 * The VFS layer wants to change one or more of an inodes attributes. Write
979 * that change out to disk.
984 static int gfs2_setattr(struct dentry *dentry, struct iattr *attr)
986 struct inode *inode = dentry->d_inode;
987 struct gfs2_inode *ip = GFS2_I(inode);
988 struct gfs2_holder i_gh;
991 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh);
996 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
999 error = inode_change_ok(inode, attr);
1003 if (attr->ia_valid & ATTR_SIZE)
1004 error = setattr_size(inode, attr);
1005 else if (attr->ia_valid & (ATTR_UID | ATTR_GID))
1006 error = setattr_chown(inode, attr);
1007 else if ((attr->ia_valid & ATTR_MODE) && IS_POSIXACL(inode))
1008 error = gfs2_acl_chmod(ip, attr);
1010 error = gfs2_setattr_simple(ip, attr);
1013 gfs2_glock_dq_uninit(&i_gh);
1015 mark_inode_dirty(inode);
1020 * gfs2_getattr - Read out an inode's attributes
1021 * @mnt: The vfsmount the inode is being accessed from
1022 * @dentry: The dentry to stat
1023 * @stat: The inode's stats
1025 * This may be called from the VFS directly, or from within GFS2 with the
1026 * inode locked, so we look to see if the glock is already locked and only
1027 * lock the glock if its not already been done. Note that its the NFS
1028 * readdirplus operation which causes this to be called (from filldir)
1029 * with the glock already held.
1034 static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry,
1037 struct inode *inode = dentry->d_inode;
1038 struct gfs2_inode *ip = GFS2_I(inode);
1039 struct gfs2_holder gh;
1043 if (gfs2_glock_is_locked_by_me(ip->i_gl) == 0) {
1044 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
1050 generic_fillattr(inode, stat);
1052 gfs2_glock_dq_uninit(&gh);
1057 static int gfs2_setxattr(struct dentry *dentry, const char *name,
1058 const void *data, size_t size, int flags)
1060 struct inode *inode = dentry->d_inode;
1061 struct gfs2_ea_request er;
1063 memset(&er, 0, sizeof(struct gfs2_ea_request));
1064 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1065 if (er.er_type == GFS2_EATYPE_UNUSED)
1067 er.er_data = (char *)data;
1068 er.er_name_len = strlen(er.er_name);
1069 er.er_data_len = size;
1070 er.er_flags = flags;
1072 gfs2_assert_warn(GFS2_SB(inode), !(er.er_flags & GFS2_ERF_MODE));
1074 return gfs2_ea_set(GFS2_I(inode), &er);
1077 static ssize_t gfs2_getxattr(struct dentry *dentry, const char *name,
1078 void *data, size_t size)
1080 struct gfs2_ea_request er;
1082 memset(&er, 0, sizeof(struct gfs2_ea_request));
1083 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1084 if (er.er_type == GFS2_EATYPE_UNUSED)
1087 er.er_name_len = strlen(er.er_name);
1088 er.er_data_len = size;
1090 return gfs2_ea_get(GFS2_I(dentry->d_inode), &er);
1093 static ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size)
1095 struct gfs2_ea_request er;
1097 memset(&er, 0, sizeof(struct gfs2_ea_request));
1098 er.er_data = (size) ? buffer : NULL;
1099 er.er_data_len = size;
1101 return gfs2_ea_list(GFS2_I(dentry->d_inode), &er);
1104 static int gfs2_removexattr(struct dentry *dentry, const char *name)
1106 struct gfs2_ea_request er;
1108 memset(&er, 0, sizeof(struct gfs2_ea_request));
1109 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1110 if (er.er_type == GFS2_EATYPE_UNUSED)
1112 er.er_name_len = strlen(er.er_name);
1114 return gfs2_ea_remove(GFS2_I(dentry->d_inode), &er);
1117 const struct inode_operations gfs2_file_iops = {
1118 .permission = gfs2_permission,
1119 .setattr = gfs2_setattr,
1120 .getattr = gfs2_getattr,
1121 .setxattr = gfs2_setxattr,
1122 .getxattr = gfs2_getxattr,
1123 .listxattr = gfs2_listxattr,
1124 .removexattr = gfs2_removexattr,
1127 const struct inode_operations gfs2_dev_iops = {
1128 .permission = gfs2_permission,
1129 .setattr = gfs2_setattr,
1130 .getattr = gfs2_getattr,
1131 .setxattr = gfs2_setxattr,
1132 .getxattr = gfs2_getxattr,
1133 .listxattr = gfs2_listxattr,
1134 .removexattr = gfs2_removexattr,
1137 const struct inode_operations gfs2_dir_iops = {
1138 .create = gfs2_create,
1139 .lookup = gfs2_lookup,
1141 .unlink = gfs2_unlink,
1142 .symlink = gfs2_symlink,
1143 .mkdir = gfs2_mkdir,
1144 .rmdir = gfs2_rmdir,
1145 .mknod = gfs2_mknod,
1146 .rename = gfs2_rename,
1147 .permission = gfs2_permission,
1148 .setattr = gfs2_setattr,
1149 .getattr = gfs2_getattr,
1150 .setxattr = gfs2_setxattr,
1151 .getxattr = gfs2_getxattr,
1152 .listxattr = gfs2_listxattr,
1153 .removexattr = gfs2_removexattr,
1156 const struct inode_operations gfs2_symlink_iops = {
1157 .readlink = gfs2_readlink,
1158 .follow_link = gfs2_follow_link,
1159 .permission = gfs2_permission,
1160 .setattr = gfs2_setattr,
1161 .getattr = gfs2_getattr,
1162 .setxattr = gfs2_setxattr,
1163 .getxattr = gfs2_getxattr,
1164 .listxattr = gfs2_listxattr,
1165 .removexattr = gfs2_removexattr,