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/sched.h>
11 #include <linux/slab.h>
12 #include <linux/spinlock.h>
13 #include <linux/completion.h>
14 #include <linux/buffer_head.h>
15 #include <linux/namei.h>
16 #include <linux/utsname.h>
18 #include <linux/xattr.h>
19 #include <linux/posix_acl.h>
20 #include <linux/gfs2_ondisk.h>
21 #include <linux/crc32.h>
22 #include <linux/lm_interface.h>
23 #include <asm/uaccess.h>
35 #include "ops_dentry.h"
36 #include "ops_inode.h"
43 * gfs2_create - Create a file
44 * @dir: The directory in which to create the file
45 * @dentry: The dentry of the new file
46 * @mode: The mode of the new file
51 static int gfs2_create(struct inode *dir, struct dentry *dentry,
52 int mode, struct nameidata *nd)
54 struct gfs2_inode *dip = GFS2_I(dir);
55 struct gfs2_sbd *sdp = GFS2_SB(dir);
56 struct gfs2_holder ghs[2];
59 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
62 inode = gfs2_createi(ghs, &dentry->d_name, S_IFREG | mode, 0);
65 if (dip->i_alloc.al_rgd)
66 gfs2_inplace_release(dip);
67 gfs2_quota_unlock(dip);
69 gfs2_glock_dq_uninit_m(2, ghs);
70 mark_inode_dirty(inode);
72 } else if (PTR_ERR(inode) != -EEXIST ||
73 (nd->intent.open.flags & O_EXCL)) {
74 gfs2_holder_uninit(ghs);
75 return PTR_ERR(inode);
78 inode = gfs2_lookupi(dir, &dentry->d_name, 0, nd);
81 gfs2_holder_uninit(ghs);
84 gfs2_holder_uninit(ghs);
85 return PTR_ERR(inode);
90 d_instantiate(dentry, inode);
96 * gfs2_lookup - Look up a filename in a directory and return its inode
97 * @dir: The directory inode
98 * @dentry: The dentry of the new inode
99 * @nd: passed from Linux VFS, ignored by us
101 * Called by the VFS layer. Lock dir and call gfs2_lookupi()
106 static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry,
107 struct nameidata *nd)
109 struct inode *inode = NULL;
111 dentry->d_op = &gfs2_dops;
113 inode = gfs2_lookupi(dir, &dentry->d_name, 0, nd);
114 if (inode && IS_ERR(inode))
115 return ERR_PTR(PTR_ERR(inode));
118 return d_splice_alias(inode, dentry);
119 d_add(dentry, inode);
125 * gfs2_link - Link to a file
126 * @old_dentry: The inode to link
127 * @dir: Add link to this directory
128 * @dentry: The name of the link
130 * Link the inode in "old_dentry" into the directory "dir" with the
136 static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
137 struct dentry *dentry)
139 struct gfs2_inode *dip = GFS2_I(dir);
140 struct gfs2_sbd *sdp = GFS2_SB(dir);
141 struct inode *inode = old_dentry->d_inode;
142 struct gfs2_inode *ip = GFS2_I(inode);
143 struct gfs2_holder ghs[2];
147 if (S_ISDIR(inode->i_mode))
150 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
151 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
153 error = gfs2_glock_nq_m(2, ghs);
157 error = permission(dir, MAY_WRITE | MAY_EXEC, NULL);
161 error = gfs2_dir_search(dir, &dentry->d_name, NULL, NULL);
172 if (!dip->i_inode.i_nlink)
175 if (dip->i_di.di_entries == (u32)-1)
178 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
181 if (!ip->i_inode.i_nlink)
184 if (ip->i_inode.i_nlink == (u32)-1)
187 alloc_required = error = gfs2_diradd_alloc_required(dir, &dentry->d_name);
192 if (alloc_required) {
193 struct gfs2_alloc *al = gfs2_alloc_get(dip);
195 error = gfs2_quota_lock(dip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
199 error = gfs2_quota_check(dip, dip->i_inode.i_uid, dip->i_inode.i_gid);
203 al->al_requested = sdp->sd_max_dirres;
205 error = gfs2_inplace_reserve(dip);
209 error = gfs2_trans_begin(sdp, sdp->sd_max_dirres +
210 al->al_rgd->rd_ri.ri_length +
211 2 * RES_DINODE + RES_STATFS +
216 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + RES_LEAF, 0);
221 error = gfs2_dir_add(dir, &dentry->d_name, &ip->i_num,
222 IF2DT(inode->i_mode));
226 error = gfs2_change_nlink(ip, +1);
232 gfs2_inplace_release(dip);
235 gfs2_quota_unlock(dip);
240 gfs2_glock_dq_m(2, ghs);
242 gfs2_holder_uninit(ghs);
243 gfs2_holder_uninit(ghs + 1);
245 atomic_inc(&inode->i_count);
246 d_instantiate(dentry, inode);
247 mark_inode_dirty(inode);
253 * gfs2_unlink - Unlink a file
254 * @dir: The inode of the directory containing the file to unlink
255 * @dentry: The file itself
257 * Unlink a file. Call gfs2_unlinki()
262 static int gfs2_unlink(struct inode *dir, struct dentry *dentry)
264 struct gfs2_inode *dip = GFS2_I(dir);
265 struct gfs2_sbd *sdp = GFS2_SB(dir);
266 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
267 struct gfs2_holder ghs[3];
268 struct gfs2_rgrpd *rgd;
269 struct gfs2_holder ri_gh;
272 error = gfs2_rindex_hold(sdp, &ri_gh);
276 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
277 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
279 rgd = gfs2_blk2rgrpd(sdp, ip->i_num.no_addr);
280 gfs2_holder_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + 2);
283 error = gfs2_glock_nq_m(3, ghs);
287 error = gfs2_unlink_ok(dip, &dentry->d_name, ip);
291 error = gfs2_trans_begin(sdp, 2*RES_DINODE + RES_LEAF + RES_RG_BIT, 0);
295 error = gfs2_dir_del(dip, &dentry->d_name);
299 error = gfs2_change_nlink(ip, -1);
304 gfs2_glock_dq_m(3, ghs);
306 gfs2_holder_uninit(ghs);
307 gfs2_holder_uninit(ghs + 1);
308 gfs2_holder_uninit(ghs + 2);
309 gfs2_glock_dq_uninit(&ri_gh);
314 * gfs2_symlink - Create a symlink
315 * @dir: The directory to create the symlink in
316 * @dentry: The dentry to put the symlink in
317 * @symname: The thing which the link points to
322 static int gfs2_symlink(struct inode *dir, struct dentry *dentry,
325 struct gfs2_inode *dip = GFS2_I(dir), *ip;
326 struct gfs2_sbd *sdp = GFS2_SB(dir);
327 struct gfs2_holder ghs[2];
329 struct buffer_head *dibh;
333 /* Must be stuffed with a null terminator for gfs2_follow_link() */
334 size = strlen(symname);
335 if (size > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode) - 1)
336 return -ENAMETOOLONG;
338 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
340 inode = gfs2_createi(ghs, &dentry->d_name, S_IFLNK | S_IRWXUGO, 0);
342 gfs2_holder_uninit(ghs);
343 return PTR_ERR(inode);
346 ip = ghs[1].gh_gl->gl_object;
348 ip->i_di.di_size = size;
350 error = gfs2_meta_inode_buffer(ip, &dibh);
352 if (!gfs2_assert_withdraw(sdp, !error)) {
353 gfs2_dinode_out(ip, dibh->b_data);
354 memcpy(dibh->b_data + sizeof(struct gfs2_dinode), symname,
360 if (dip->i_alloc.al_rgd)
361 gfs2_inplace_release(dip);
362 gfs2_quota_unlock(dip);
365 gfs2_glock_dq_uninit_m(2, ghs);
367 d_instantiate(dentry, inode);
368 mark_inode_dirty(inode);
374 * gfs2_mkdir - Make a directory
375 * @dir: The parent directory of the new one
376 * @dentry: The dentry of the new directory
377 * @mode: The mode of the new directory
382 static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode)
384 struct gfs2_inode *dip = GFS2_I(dir), *ip;
385 struct gfs2_sbd *sdp = GFS2_SB(dir);
386 struct gfs2_holder ghs[2];
388 struct buffer_head *dibh;
391 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
393 inode = gfs2_createi(ghs, &dentry->d_name, S_IFDIR | mode, 0);
395 gfs2_holder_uninit(ghs);
396 return PTR_ERR(inode);
399 ip = ghs[1].gh_gl->gl_object;
401 ip->i_inode.i_nlink = 2;
402 ip->i_di.di_size = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode);
403 ip->i_di.di_flags |= GFS2_DIF_JDATA;
404 ip->i_di.di_entries = 2;
406 error = gfs2_meta_inode_buffer(ip, &dibh);
408 if (!gfs2_assert_withdraw(sdp, !error)) {
409 struct gfs2_dinode *di = (struct gfs2_dinode *)dibh->b_data;
410 struct gfs2_dirent *dent = (struct gfs2_dirent *)(di+1);
413 gfs2_str2qstr(&str, ".");
414 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
415 gfs2_qstr2dirent(&str, GFS2_DIRENT_SIZE(str.len), dent);
416 dent->de_inum = di->di_num; /* already GFS2 endian */
417 dent->de_type = cpu_to_be16(DT_DIR);
418 di->di_entries = cpu_to_be32(1);
420 gfs2_str2qstr(&str, "..");
421 dent = (struct gfs2_dirent *)((char*)dent + GFS2_DIRENT_SIZE(1));
422 gfs2_qstr2dirent(&str, dibh->b_size - GFS2_DIRENT_SIZE(1) - sizeof(struct gfs2_dinode), dent);
424 gfs2_inum_out(&dip->i_num, &dent->de_inum);
425 dent->de_type = cpu_to_be16(DT_DIR);
427 gfs2_dinode_out(ip, di);
432 error = gfs2_change_nlink(dip, +1);
433 gfs2_assert_withdraw(sdp, !error); /* dip already pinned */
436 if (dip->i_alloc.al_rgd)
437 gfs2_inplace_release(dip);
438 gfs2_quota_unlock(dip);
441 gfs2_glock_dq_uninit_m(2, ghs);
443 d_instantiate(dentry, inode);
444 mark_inode_dirty(inode);
450 * gfs2_rmdir - Remove a directory
451 * @dir: The parent directory of the directory to be removed
452 * @dentry: The dentry of the directory to remove
454 * Remove a directory. Call gfs2_rmdiri()
459 static int gfs2_rmdir(struct inode *dir, struct dentry *dentry)
461 struct gfs2_inode *dip = GFS2_I(dir);
462 struct gfs2_sbd *sdp = GFS2_SB(dir);
463 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
464 struct gfs2_holder ghs[3];
465 struct gfs2_rgrpd *rgd;
466 struct gfs2_holder ri_gh;
470 error = gfs2_rindex_hold(sdp, &ri_gh);
473 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
474 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
476 rgd = gfs2_blk2rgrpd(sdp, ip->i_num.no_addr);
477 gfs2_holder_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + 2);
479 error = gfs2_glock_nq_m(3, ghs);
483 error = gfs2_unlink_ok(dip, &dentry->d_name, ip);
487 if (ip->i_di.di_entries < 2) {
488 if (gfs2_consist_inode(ip))
489 gfs2_dinode_print(ip);
493 if (ip->i_di.di_entries > 2) {
498 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + 3 * RES_LEAF + RES_RG_BIT, 0);
502 error = gfs2_rmdiri(dip, &dentry->d_name, ip);
507 gfs2_glock_dq_m(3, ghs);
509 gfs2_holder_uninit(ghs);
510 gfs2_holder_uninit(ghs + 1);
511 gfs2_holder_uninit(ghs + 2);
512 gfs2_glock_dq_uninit(&ri_gh);
517 * gfs2_mknod - Make a special file
518 * @dir: The directory in which the special file will reside
519 * @dentry: The dentry of the special file
520 * @mode: The mode of the special file
521 * @rdev: The device specification of the special file
525 static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode,
528 struct gfs2_inode *dip = GFS2_I(dir);
529 struct gfs2_sbd *sdp = GFS2_SB(dir);
530 struct gfs2_holder ghs[2];
533 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
535 inode = gfs2_createi(ghs, &dentry->d_name, mode, dev);
537 gfs2_holder_uninit(ghs);
538 return PTR_ERR(inode);
542 if (dip->i_alloc.al_rgd)
543 gfs2_inplace_release(dip);
544 gfs2_quota_unlock(dip);
547 gfs2_glock_dq_uninit_m(2, ghs);
549 d_instantiate(dentry, inode);
550 mark_inode_dirty(inode);
556 * gfs2_rename - Rename a file
557 * @odir: Parent directory of old file name
558 * @odentry: The old dentry of the file
559 * @ndir: Parent directory of new file name
560 * @ndentry: The new dentry of the file
565 static int gfs2_rename(struct inode *odir, struct dentry *odentry,
566 struct inode *ndir, struct dentry *ndentry)
568 struct gfs2_inode *odip = GFS2_I(odir);
569 struct gfs2_inode *ndip = GFS2_I(ndir);
570 struct gfs2_inode *ip = GFS2_I(odentry->d_inode);
571 struct gfs2_inode *nip = NULL;
572 struct gfs2_sbd *sdp = GFS2_SB(odir);
573 struct gfs2_holder ghs[5], r_gh;
574 struct gfs2_rgrpd *nrgd;
581 if (ndentry->d_inode) {
582 nip = GFS2_I(ndentry->d_inode);
587 /* Make sure we aren't trying to move a dirctory into it's subdir */
589 if (S_ISDIR(ip->i_inode.i_mode) && odip != ndip) {
592 error = gfs2_glock_nq_init(sdp->sd_rename_gl, LM_ST_EXCLUSIVE, 0,
597 error = gfs2_ok_to_move(ip, ndip);
603 gfs2_holder_init(odip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
605 gfs2_holder_init(ndip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
608 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
612 gfs2_holder_init(nip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
614 /* grab the resource lock for unlink flag twiddling
615 * this is the case of the target file already existing
616 * so we unlink before doing the rename
618 nrgd = gfs2_blk2rgrpd(sdp, nip->i_num.no_addr);
620 gfs2_holder_init(nrgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh++);
623 error = gfs2_glock_nq_m(num_gh, ghs);
627 /* Check out the old directory */
629 error = gfs2_unlink_ok(odip, &odentry->d_name, ip);
633 /* Check out the new directory */
636 error = gfs2_unlink_ok(ndip, &ndentry->d_name, nip);
640 if (S_ISDIR(nip->i_inode.i_mode)) {
641 if (nip->i_di.di_entries < 2) {
642 if (gfs2_consist_inode(nip))
643 gfs2_dinode_print(nip);
647 if (nip->i_di.di_entries > 2) {
653 error = permission(ndir, MAY_WRITE | MAY_EXEC, NULL);
657 error = gfs2_dir_search(ndir, &ndentry->d_name, NULL, NULL);
669 if (!ndip->i_inode.i_nlink) {
673 if (ndip->i_di.di_entries == (u32)-1) {
677 if (S_ISDIR(ip->i_inode.i_mode) &&
678 ndip->i_inode.i_nlink == (u32)-1) {
685 /* Check out the dir to be renamed */
688 error = permission(odentry->d_inode, MAY_WRITE, NULL);
693 alloc_required = error = gfs2_diradd_alloc_required(ndir, &ndentry->d_name);
698 if (alloc_required) {
699 struct gfs2_alloc *al = gfs2_alloc_get(ndip);
701 error = gfs2_quota_lock(ndip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
705 error = gfs2_quota_check(ndip, ndip->i_inode.i_uid, ndip->i_inode.i_gid);
709 al->al_requested = sdp->sd_max_dirres;
711 error = gfs2_inplace_reserve(ndip);
715 error = gfs2_trans_begin(sdp, sdp->sd_max_dirres +
716 al->al_rgd->rd_ri.ri_length +
717 4 * RES_DINODE + 4 * RES_LEAF +
718 RES_STATFS + RES_QUOTA + 4, 0);
722 error = gfs2_trans_begin(sdp, 4 * RES_DINODE +
723 5 * RES_LEAF + 4, 0);
728 /* Remove the target file, if it exists */
731 if (S_ISDIR(nip->i_inode.i_mode))
732 error = gfs2_rmdiri(ndip, &ndentry->d_name, nip);
734 error = gfs2_dir_del(ndip, &ndentry->d_name);
737 error = gfs2_change_nlink(nip, -1);
745 gfs2_str2qstr(&name, "..");
747 error = gfs2_change_nlink(ndip, +1);
750 error = gfs2_change_nlink(odip, -1);
754 error = gfs2_dir_mvino(ip, &name, &ndip->i_num, DT_DIR);
758 struct buffer_head *dibh;
759 error = gfs2_meta_inode_buffer(ip, &dibh);
762 ip->i_inode.i_ctime = CURRENT_TIME_SEC;
763 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
764 gfs2_dinode_out(ip, dibh->b_data);
768 error = gfs2_dir_del(odip, &odentry->d_name);
772 error = gfs2_dir_add(ndir, &ndentry->d_name, &ip->i_num,
773 IF2DT(ip->i_inode.i_mode));
781 gfs2_inplace_release(ndip);
784 gfs2_quota_unlock(ndip);
787 gfs2_alloc_put(ndip);
789 gfs2_glock_dq_m(num_gh, ghs);
791 for (x = 0; x < num_gh; x++)
792 gfs2_holder_uninit(ghs + x);
795 gfs2_glock_dq_uninit(&r_gh);
801 * gfs2_readlink - Read the value of a symlink
802 * @dentry: the symlink
803 * @buf: the buffer to read the symlink data into
804 * @size: the size of the buffer
809 static int gfs2_readlink(struct dentry *dentry, char __user *user_buf,
812 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
813 char array[GFS2_FAST_NAME_SIZE], *buf = array;
814 unsigned int len = GFS2_FAST_NAME_SIZE;
817 error = gfs2_readlinki(ip, &buf, &len);
821 if (user_size > len - 1)
824 if (copy_to_user(user_buf, buf, user_size))
836 * gfs2_follow_link - Follow a symbolic link
837 * @dentry: The dentry of the link
838 * @nd: Data that we pass to vfs_follow_link()
840 * This can handle symlinks of any size. It is optimised for symlinks
841 * under GFS2_FAST_NAME_SIZE.
843 * Returns: 0 on success or error code
846 static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd)
848 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
849 char array[GFS2_FAST_NAME_SIZE], *buf = array;
850 unsigned int len = GFS2_FAST_NAME_SIZE;
853 error = gfs2_readlinki(ip, &buf, &len);
855 error = vfs_follow_link(nd, buf);
860 return ERR_PTR(error);
867 * @nd: passed from Linux VFS, ignored by us
869 * This may be called from the VFS directly, or from within GFS2 with the
870 * inode locked, so we look to see if the glock is already locked and only
871 * lock the glock if its not already been done.
876 static int gfs2_permission(struct inode *inode, int mask, struct nameidata *nd)
878 struct gfs2_inode *ip = GFS2_I(inode);
879 struct gfs2_holder i_gh;
883 if (gfs2_glock_is_locked_by_me(ip->i_gl) == 0) {
884 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh);
890 error = generic_permission(inode, mask, gfs2_check_acl);
892 gfs2_glock_dq_uninit(&i_gh);
897 static int setattr_size(struct inode *inode, struct iattr *attr)
899 struct gfs2_inode *ip = GFS2_I(inode);
902 if (attr->ia_size != ip->i_di.di_size) {
903 error = vmtruncate(inode, attr->ia_size);
908 error = gfs2_truncatei(ip, attr->ia_size);
915 static int setattr_chown(struct inode *inode, struct iattr *attr)
917 struct gfs2_inode *ip = GFS2_I(inode);
918 struct gfs2_sbd *sdp = GFS2_SB(inode);
919 struct buffer_head *dibh;
920 u32 ouid, ogid, nuid, ngid;
928 if (!(attr->ia_valid & ATTR_UID) || ouid == nuid)
929 ouid = nuid = NO_QUOTA_CHANGE;
930 if (!(attr->ia_valid & ATTR_GID) || ogid == ngid)
931 ogid = ngid = NO_QUOTA_CHANGE;
935 error = gfs2_quota_lock(ip, nuid, ngid);
939 if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) {
940 error = gfs2_quota_check(ip, nuid, ngid);
945 error = gfs2_trans_begin(sdp, RES_DINODE + 2 * RES_QUOTA, 0);
949 error = gfs2_meta_inode_buffer(ip, &dibh);
953 error = inode_setattr(inode, attr);
954 gfs2_assert_warn(sdp, !error);
956 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
957 gfs2_dinode_out(ip, dibh->b_data);
960 if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) {
961 gfs2_quota_change(ip, -ip->i_di.di_blocks, ouid, ogid);
962 gfs2_quota_change(ip, ip->i_di.di_blocks, nuid, ngid);
968 gfs2_quota_unlock(ip);
975 * gfs2_setattr - Change attributes on an inode
976 * @dentry: The dentry which is changing
977 * @attr: The structure describing the change
979 * The VFS layer wants to change one or more of an inodes attributes. Write
980 * that change out to disk.
985 static int gfs2_setattr(struct dentry *dentry, struct iattr *attr)
987 struct inode *inode = dentry->d_inode;
988 struct gfs2_inode *ip = GFS2_I(inode);
989 struct gfs2_holder i_gh;
992 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh);
997 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1000 error = inode_change_ok(inode, attr);
1004 if (attr->ia_valid & ATTR_SIZE)
1005 error = setattr_size(inode, attr);
1006 else if (attr->ia_valid & (ATTR_UID | ATTR_GID))
1007 error = setattr_chown(inode, attr);
1008 else if ((attr->ia_valid & ATTR_MODE) && IS_POSIXACL(inode))
1009 error = gfs2_acl_chmod(ip, attr);
1011 error = gfs2_setattr_simple(ip, attr);
1014 gfs2_glock_dq_uninit(&i_gh);
1016 mark_inode_dirty(inode);
1021 * gfs2_getattr - Read out an inode's attributes
1022 * @mnt: The vfsmount the inode is being accessed from
1023 * @dentry: The dentry to stat
1024 * @stat: The inode's stats
1026 * This may be called from the VFS directly, or from within GFS2 with the
1027 * inode locked, so we look to see if the glock is already locked and only
1028 * lock the glock if its not already been done. Note that its the NFS
1029 * readdirplus operation which causes this to be called (from filldir)
1030 * with the glock already held.
1035 static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry,
1038 struct inode *inode = dentry->d_inode;
1039 struct gfs2_inode *ip = GFS2_I(inode);
1040 struct gfs2_holder gh;
1044 if (gfs2_glock_is_locked_by_me(ip->i_gl) == 0) {
1045 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
1051 generic_fillattr(inode, stat);
1053 gfs2_glock_dq_uninit(&gh);
1058 static int gfs2_setxattr(struct dentry *dentry, const char *name,
1059 const void *data, size_t size, int flags)
1061 struct inode *inode = dentry->d_inode;
1062 struct gfs2_ea_request er;
1064 memset(&er, 0, sizeof(struct gfs2_ea_request));
1065 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1066 if (er.er_type == GFS2_EATYPE_UNUSED)
1068 er.er_data = (char *)data;
1069 er.er_name_len = strlen(er.er_name);
1070 er.er_data_len = size;
1071 er.er_flags = flags;
1073 gfs2_assert_warn(GFS2_SB(inode), !(er.er_flags & GFS2_ERF_MODE));
1075 return gfs2_ea_set(GFS2_I(inode), &er);
1078 static ssize_t gfs2_getxattr(struct dentry *dentry, const char *name,
1079 void *data, size_t size)
1081 struct gfs2_ea_request er;
1083 memset(&er, 0, sizeof(struct gfs2_ea_request));
1084 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1085 if (er.er_type == GFS2_EATYPE_UNUSED)
1088 er.er_name_len = strlen(er.er_name);
1089 er.er_data_len = size;
1091 return gfs2_ea_get(GFS2_I(dentry->d_inode), &er);
1094 static ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size)
1096 struct gfs2_ea_request er;
1098 memset(&er, 0, sizeof(struct gfs2_ea_request));
1099 er.er_data = (size) ? buffer : NULL;
1100 er.er_data_len = size;
1102 return gfs2_ea_list(GFS2_I(dentry->d_inode), &er);
1105 static int gfs2_removexattr(struct dentry *dentry, const char *name)
1107 struct gfs2_ea_request er;
1109 memset(&er, 0, sizeof(struct gfs2_ea_request));
1110 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1111 if (er.er_type == GFS2_EATYPE_UNUSED)
1113 er.er_name_len = strlen(er.er_name);
1115 return gfs2_ea_remove(GFS2_I(dentry->d_inode), &er);
1118 struct inode_operations gfs2_file_iops = {
1119 .permission = gfs2_permission,
1120 .setattr = gfs2_setattr,
1121 .getattr = gfs2_getattr,
1122 .setxattr = gfs2_setxattr,
1123 .getxattr = gfs2_getxattr,
1124 .listxattr = gfs2_listxattr,
1125 .removexattr = gfs2_removexattr,
1128 struct inode_operations gfs2_dev_iops = {
1129 .permission = gfs2_permission,
1130 .setattr = gfs2_setattr,
1131 .getattr = gfs2_getattr,
1132 .setxattr = gfs2_setxattr,
1133 .getxattr = gfs2_getxattr,
1134 .listxattr = gfs2_listxattr,
1135 .removexattr = gfs2_removexattr,
1138 struct inode_operations gfs2_dir_iops = {
1139 .create = gfs2_create,
1140 .lookup = gfs2_lookup,
1142 .unlink = gfs2_unlink,
1143 .symlink = gfs2_symlink,
1144 .mkdir = gfs2_mkdir,
1145 .rmdir = gfs2_rmdir,
1146 .mknod = gfs2_mknod,
1147 .rename = gfs2_rename,
1148 .permission = gfs2_permission,
1149 .setattr = gfs2_setattr,
1150 .getattr = gfs2_getattr,
1151 .setxattr = gfs2_setxattr,
1152 .getxattr = gfs2_getxattr,
1153 .listxattr = gfs2_listxattr,
1154 .removexattr = gfs2_removexattr,
1157 struct inode_operations gfs2_symlink_iops = {
1158 .readlink = gfs2_readlink,
1159 .follow_link = gfs2_follow_link,
1160 .permission = gfs2_permission,
1161 .setattr = gfs2_setattr,
1162 .getattr = gfs2_getattr,
1163 .setxattr = gfs2_setxattr,
1164 .getxattr = gfs2_getxattr,
1165 .listxattr = gfs2_listxattr,
1166 .removexattr = gfs2_removexattr,