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_check(dir, &dentry->d_name, 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_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, IF2DT(inode->i_mode));
224 error = gfs2_change_nlink(ip, +1);
230 gfs2_inplace_release(dip);
233 gfs2_quota_unlock(dip);
238 gfs2_glock_dq_m(2, ghs);
240 gfs2_holder_uninit(ghs);
241 gfs2_holder_uninit(ghs + 1);
243 atomic_inc(&inode->i_count);
244 d_instantiate(dentry, inode);
245 mark_inode_dirty(inode);
251 * gfs2_unlink - Unlink a file
252 * @dir: The inode of the directory containing the file to unlink
253 * @dentry: The file itself
255 * Unlink a file. Call gfs2_unlinki()
260 static int gfs2_unlink(struct inode *dir, struct dentry *dentry)
262 struct gfs2_inode *dip = GFS2_I(dir);
263 struct gfs2_sbd *sdp = GFS2_SB(dir);
264 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
265 struct gfs2_holder ghs[3];
266 struct gfs2_rgrpd *rgd;
267 struct gfs2_holder ri_gh;
270 error = gfs2_rindex_hold(sdp, &ri_gh);
274 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
275 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
277 rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr);
278 gfs2_holder_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + 2);
281 error = gfs2_glock_nq_m(3, ghs);
285 error = gfs2_unlink_ok(dip, &dentry->d_name, ip);
289 error = gfs2_trans_begin(sdp, 2*RES_DINODE + RES_LEAF + RES_RG_BIT, 0);
293 error = gfs2_dir_del(dip, &dentry->d_name);
297 error = gfs2_change_nlink(ip, -1);
302 gfs2_glock_dq_m(3, ghs);
304 gfs2_holder_uninit(ghs);
305 gfs2_holder_uninit(ghs + 1);
306 gfs2_holder_uninit(ghs + 2);
307 gfs2_glock_dq_uninit(&ri_gh);
312 * gfs2_symlink - Create a symlink
313 * @dir: The directory to create the symlink in
314 * @dentry: The dentry to put the symlink in
315 * @symname: The thing which the link points to
320 static int gfs2_symlink(struct inode *dir, struct dentry *dentry,
323 struct gfs2_inode *dip = GFS2_I(dir), *ip;
324 struct gfs2_sbd *sdp = GFS2_SB(dir);
325 struct gfs2_holder ghs[2];
327 struct buffer_head *dibh;
331 /* Must be stuffed with a null terminator for gfs2_follow_link() */
332 size = strlen(symname);
333 if (size > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode) - 1)
334 return -ENAMETOOLONG;
336 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
338 inode = gfs2_createi(ghs, &dentry->d_name, S_IFLNK | S_IRWXUGO, 0);
340 gfs2_holder_uninit(ghs);
341 return PTR_ERR(inode);
344 ip = ghs[1].gh_gl->gl_object;
346 ip->i_di.di_size = size;
348 error = gfs2_meta_inode_buffer(ip, &dibh);
350 if (!gfs2_assert_withdraw(sdp, !error)) {
351 gfs2_dinode_out(ip, dibh->b_data);
352 memcpy(dibh->b_data + sizeof(struct gfs2_dinode), symname,
358 if (dip->i_alloc.al_rgd)
359 gfs2_inplace_release(dip);
360 gfs2_quota_unlock(dip);
363 gfs2_glock_dq_uninit_m(2, ghs);
365 d_instantiate(dentry, inode);
366 mark_inode_dirty(inode);
372 * gfs2_mkdir - Make a directory
373 * @dir: The parent directory of the new one
374 * @dentry: The dentry of the new directory
375 * @mode: The mode of the new directory
380 static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode)
382 struct gfs2_inode *dip = GFS2_I(dir), *ip;
383 struct gfs2_sbd *sdp = GFS2_SB(dir);
384 struct gfs2_holder ghs[2];
386 struct buffer_head *dibh;
389 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
391 inode = gfs2_createi(ghs, &dentry->d_name, S_IFDIR | mode, 0);
393 gfs2_holder_uninit(ghs);
394 return PTR_ERR(inode);
397 ip = ghs[1].gh_gl->gl_object;
399 ip->i_inode.i_nlink = 2;
400 ip->i_di.di_size = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode);
401 ip->i_di.di_flags |= GFS2_DIF_JDATA;
402 ip->i_di.di_entries = 2;
404 error = gfs2_meta_inode_buffer(ip, &dibh);
406 if (!gfs2_assert_withdraw(sdp, !error)) {
407 struct gfs2_dinode *di = (struct gfs2_dinode *)dibh->b_data;
408 struct gfs2_dirent *dent = (struct gfs2_dirent *)(di+1);
411 gfs2_str2qstr(&str, ".");
412 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
413 gfs2_qstr2dirent(&str, GFS2_DIRENT_SIZE(str.len), dent);
414 dent->de_inum = di->di_num; /* already GFS2 endian */
415 dent->de_type = cpu_to_be16(DT_DIR);
416 di->di_entries = cpu_to_be32(1);
418 gfs2_str2qstr(&str, "..");
419 dent = (struct gfs2_dirent *)((char*)dent + GFS2_DIRENT_SIZE(1));
420 gfs2_qstr2dirent(&str, dibh->b_size - GFS2_DIRENT_SIZE(1) - sizeof(struct gfs2_dinode), dent);
422 gfs2_inum_out(dip, dent);
423 dent->de_type = cpu_to_be16(DT_DIR);
425 gfs2_dinode_out(ip, di);
430 error = gfs2_change_nlink(dip, +1);
431 gfs2_assert_withdraw(sdp, !error); /* dip already pinned */
434 if (dip->i_alloc.al_rgd)
435 gfs2_inplace_release(dip);
436 gfs2_quota_unlock(dip);
439 gfs2_glock_dq_uninit_m(2, ghs);
441 d_instantiate(dentry, inode);
442 mark_inode_dirty(inode);
448 * gfs2_rmdir - Remove a directory
449 * @dir: The parent directory of the directory to be removed
450 * @dentry: The dentry of the directory to remove
452 * Remove a directory. Call gfs2_rmdiri()
457 static int gfs2_rmdir(struct inode *dir, struct dentry *dentry)
459 struct gfs2_inode *dip = GFS2_I(dir);
460 struct gfs2_sbd *sdp = GFS2_SB(dir);
461 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
462 struct gfs2_holder ghs[3];
463 struct gfs2_rgrpd *rgd;
464 struct gfs2_holder ri_gh;
468 error = gfs2_rindex_hold(sdp, &ri_gh);
471 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
472 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
474 rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr);
475 gfs2_holder_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + 2);
477 error = gfs2_glock_nq_m(3, ghs);
481 error = gfs2_unlink_ok(dip, &dentry->d_name, ip);
485 if (ip->i_di.di_entries < 2) {
486 if (gfs2_consist_inode(ip))
487 gfs2_dinode_print(ip);
491 if (ip->i_di.di_entries > 2) {
496 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + 3 * RES_LEAF + RES_RG_BIT, 0);
500 error = gfs2_rmdiri(dip, &dentry->d_name, ip);
505 gfs2_glock_dq_m(3, ghs);
507 gfs2_holder_uninit(ghs);
508 gfs2_holder_uninit(ghs + 1);
509 gfs2_holder_uninit(ghs + 2);
510 gfs2_glock_dq_uninit(&ri_gh);
515 * gfs2_mknod - Make a special file
516 * @dir: The directory in which the special file will reside
517 * @dentry: The dentry of the special file
518 * @mode: The mode of the special file
519 * @rdev: The device specification of the special file
523 static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode,
526 struct gfs2_inode *dip = GFS2_I(dir);
527 struct gfs2_sbd *sdp = GFS2_SB(dir);
528 struct gfs2_holder ghs[2];
531 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
533 inode = gfs2_createi(ghs, &dentry->d_name, mode, dev);
535 gfs2_holder_uninit(ghs);
536 return PTR_ERR(inode);
540 if (dip->i_alloc.al_rgd)
541 gfs2_inplace_release(dip);
542 gfs2_quota_unlock(dip);
545 gfs2_glock_dq_uninit_m(2, ghs);
547 d_instantiate(dentry, inode);
548 mark_inode_dirty(inode);
554 * gfs2_rename - Rename a file
555 * @odir: Parent directory of old file name
556 * @odentry: The old dentry of the file
557 * @ndir: Parent directory of new file name
558 * @ndentry: The new dentry of the file
563 static int gfs2_rename(struct inode *odir, struct dentry *odentry,
564 struct inode *ndir, struct dentry *ndentry)
566 struct gfs2_inode *odip = GFS2_I(odir);
567 struct gfs2_inode *ndip = GFS2_I(ndir);
568 struct gfs2_inode *ip = GFS2_I(odentry->d_inode);
569 struct gfs2_inode *nip = NULL;
570 struct gfs2_sbd *sdp = GFS2_SB(odir);
571 struct gfs2_holder ghs[5], r_gh;
572 struct gfs2_rgrpd *nrgd;
579 if (ndentry->d_inode) {
580 nip = GFS2_I(ndentry->d_inode);
585 /* Make sure we aren't trying to move a dirctory into it's subdir */
587 if (S_ISDIR(ip->i_inode.i_mode) && odip != ndip) {
590 error = gfs2_glock_nq_init(sdp->sd_rename_gl, LM_ST_EXCLUSIVE, 0,
595 error = gfs2_ok_to_move(ip, ndip);
601 gfs2_holder_init(odip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
603 gfs2_holder_init(ndip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
606 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
610 gfs2_holder_init(nip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
612 /* grab the resource lock for unlink flag twiddling
613 * this is the case of the target file already existing
614 * so we unlink before doing the rename
616 nrgd = gfs2_blk2rgrpd(sdp, nip->i_no_addr);
618 gfs2_holder_init(nrgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh++);
621 error = gfs2_glock_nq_m(num_gh, ghs);
625 /* Check out the old directory */
627 error = gfs2_unlink_ok(odip, &odentry->d_name, ip);
631 /* Check out the new directory */
634 error = gfs2_unlink_ok(ndip, &ndentry->d_name, nip);
638 if (S_ISDIR(nip->i_inode.i_mode)) {
639 if (nip->i_di.di_entries < 2) {
640 if (gfs2_consist_inode(nip))
641 gfs2_dinode_print(nip);
645 if (nip->i_di.di_entries > 2) {
651 error = permission(ndir, MAY_WRITE | MAY_EXEC, NULL);
655 error = gfs2_dir_check(ndir, &ndentry->d_name, NULL);
667 if (!ndip->i_inode.i_nlink) {
671 if (ndip->i_di.di_entries == (u32)-1) {
675 if (S_ISDIR(ip->i_inode.i_mode) &&
676 ndip->i_inode.i_nlink == (u32)-1) {
683 /* Check out the dir to be renamed */
686 error = permission(odentry->d_inode, MAY_WRITE, NULL);
691 alloc_required = error = gfs2_diradd_alloc_required(ndir, &ndentry->d_name);
696 if (alloc_required) {
697 struct gfs2_alloc *al = gfs2_alloc_get(ndip);
699 error = gfs2_quota_lock(ndip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
703 error = gfs2_quota_check(ndip, ndip->i_inode.i_uid, ndip->i_inode.i_gid);
707 al->al_requested = sdp->sd_max_dirres;
709 error = gfs2_inplace_reserve(ndip);
713 error = gfs2_trans_begin(sdp, sdp->sd_max_dirres +
714 al->al_rgd->rd_length +
715 4 * RES_DINODE + 4 * RES_LEAF +
716 RES_STATFS + RES_QUOTA + 4, 0);
720 error = gfs2_trans_begin(sdp, 4 * RES_DINODE +
721 5 * RES_LEAF + 4, 0);
726 /* Remove the target file, if it exists */
729 if (S_ISDIR(nip->i_inode.i_mode))
730 error = gfs2_rmdiri(ndip, &ndentry->d_name, nip);
732 error = gfs2_dir_del(ndip, &ndentry->d_name);
735 error = gfs2_change_nlink(nip, -1);
743 gfs2_str2qstr(&name, "..");
745 error = gfs2_change_nlink(ndip, +1);
748 error = gfs2_change_nlink(odip, -1);
752 error = gfs2_dir_mvino(ip, &name, ndip, DT_DIR);
756 struct buffer_head *dibh;
757 error = gfs2_meta_inode_buffer(ip, &dibh);
760 ip->i_inode.i_ctime = CURRENT_TIME;
761 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
762 gfs2_dinode_out(ip, dibh->b_data);
766 error = gfs2_dir_del(odip, &odentry->d_name);
770 error = gfs2_dir_add(ndir, &ndentry->d_name, ip, IF2DT(ip->i_inode.i_mode));
778 gfs2_inplace_release(ndip);
781 gfs2_quota_unlock(ndip);
784 gfs2_alloc_put(ndip);
786 gfs2_glock_dq_m(num_gh, ghs);
788 for (x = 0; x < num_gh; x++)
789 gfs2_holder_uninit(ghs + x);
792 gfs2_glock_dq_uninit(&r_gh);
798 * gfs2_readlink - Read the value of a symlink
799 * @dentry: the symlink
800 * @buf: the buffer to read the symlink data into
801 * @size: the size of the buffer
806 static int gfs2_readlink(struct dentry *dentry, char __user *user_buf,
809 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
810 char array[GFS2_FAST_NAME_SIZE], *buf = array;
811 unsigned int len = GFS2_FAST_NAME_SIZE;
814 error = gfs2_readlinki(ip, &buf, &len);
818 if (user_size > len - 1)
821 if (copy_to_user(user_buf, buf, user_size))
833 * gfs2_follow_link - Follow a symbolic link
834 * @dentry: The dentry of the link
835 * @nd: Data that we pass to vfs_follow_link()
837 * This can handle symlinks of any size. It is optimised for symlinks
838 * under GFS2_FAST_NAME_SIZE.
840 * Returns: 0 on success or error code
843 static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd)
845 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
846 char array[GFS2_FAST_NAME_SIZE], *buf = array;
847 unsigned int len = GFS2_FAST_NAME_SIZE;
850 error = gfs2_readlinki(ip, &buf, &len);
852 error = vfs_follow_link(nd, buf);
857 return ERR_PTR(error);
864 * @nd: passed from Linux VFS, ignored by us
866 * This may be called from the VFS directly, or from within GFS2 with the
867 * inode locked, so we look to see if the glock is already locked and only
868 * lock the glock if its not already been done.
873 static int gfs2_permission(struct inode *inode, int mask, struct nameidata *nd)
875 struct gfs2_inode *ip = GFS2_I(inode);
876 struct gfs2_holder i_gh;
880 if (gfs2_glock_is_locked_by_me(ip->i_gl) == 0) {
881 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh);
887 error = generic_permission(inode, mask, gfs2_check_acl);
889 gfs2_glock_dq_uninit(&i_gh);
894 static int setattr_size(struct inode *inode, struct iattr *attr)
896 struct gfs2_inode *ip = GFS2_I(inode);
899 if (attr->ia_size != ip->i_di.di_size) {
900 error = vmtruncate(inode, attr->ia_size);
905 error = gfs2_truncatei(ip, attr->ia_size);
912 static int setattr_chown(struct inode *inode, struct iattr *attr)
914 struct gfs2_inode *ip = GFS2_I(inode);
915 struct gfs2_sbd *sdp = GFS2_SB(inode);
916 struct buffer_head *dibh;
917 u32 ouid, ogid, nuid, ngid;
925 if (!(attr->ia_valid & ATTR_UID) || ouid == nuid)
926 ouid = nuid = NO_QUOTA_CHANGE;
927 if (!(attr->ia_valid & ATTR_GID) || ogid == ngid)
928 ogid = ngid = NO_QUOTA_CHANGE;
932 error = gfs2_quota_lock(ip, nuid, ngid);
936 if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) {
937 error = gfs2_quota_check(ip, nuid, ngid);
942 error = gfs2_trans_begin(sdp, RES_DINODE + 2 * RES_QUOTA, 0);
946 error = gfs2_meta_inode_buffer(ip, &dibh);
950 error = inode_setattr(inode, attr);
951 gfs2_assert_warn(sdp, !error);
953 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
954 gfs2_dinode_out(ip, dibh->b_data);
957 if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) {
958 gfs2_quota_change(ip, -ip->i_di.di_blocks, ouid, ogid);
959 gfs2_quota_change(ip, ip->i_di.di_blocks, nuid, ngid);
965 gfs2_quota_unlock(ip);
972 * gfs2_setattr - Change attributes on an inode
973 * @dentry: The dentry which is changing
974 * @attr: The structure describing the change
976 * The VFS layer wants to change one or more of an inodes attributes. Write
977 * that change out to disk.
982 static int gfs2_setattr(struct dentry *dentry, struct iattr *attr)
984 struct inode *inode = dentry->d_inode;
985 struct gfs2_inode *ip = GFS2_I(inode);
986 struct gfs2_holder i_gh;
989 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh);
994 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
997 error = inode_change_ok(inode, attr);
1001 if (attr->ia_valid & ATTR_SIZE)
1002 error = setattr_size(inode, attr);
1003 else if (attr->ia_valid & (ATTR_UID | ATTR_GID))
1004 error = setattr_chown(inode, attr);
1005 else if ((attr->ia_valid & ATTR_MODE) && IS_POSIXACL(inode))
1006 error = gfs2_acl_chmod(ip, attr);
1008 error = gfs2_setattr_simple(ip, attr);
1011 gfs2_glock_dq_uninit(&i_gh);
1013 mark_inode_dirty(inode);
1018 * gfs2_getattr - Read out an inode's attributes
1019 * @mnt: The vfsmount the inode is being accessed from
1020 * @dentry: The dentry to stat
1021 * @stat: The inode's stats
1023 * This may be called from the VFS directly, or from within GFS2 with the
1024 * inode locked, so we look to see if the glock is already locked and only
1025 * lock the glock if its not already been done. Note that its the NFS
1026 * readdirplus operation which causes this to be called (from filldir)
1027 * with the glock already held.
1032 static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry,
1035 struct inode *inode = dentry->d_inode;
1036 struct gfs2_inode *ip = GFS2_I(inode);
1037 struct gfs2_holder gh;
1041 if (gfs2_glock_is_locked_by_me(ip->i_gl) == 0) {
1042 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
1048 generic_fillattr(inode, stat);
1050 gfs2_glock_dq_uninit(&gh);
1055 static int gfs2_setxattr(struct dentry *dentry, const char *name,
1056 const void *data, size_t size, int flags)
1058 struct inode *inode = dentry->d_inode;
1059 struct gfs2_ea_request er;
1061 memset(&er, 0, sizeof(struct gfs2_ea_request));
1062 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1063 if (er.er_type == GFS2_EATYPE_UNUSED)
1065 er.er_data = (char *)data;
1066 er.er_name_len = strlen(er.er_name);
1067 er.er_data_len = size;
1068 er.er_flags = flags;
1070 gfs2_assert_warn(GFS2_SB(inode), !(er.er_flags & GFS2_ERF_MODE));
1072 return gfs2_ea_set(GFS2_I(inode), &er);
1075 static ssize_t gfs2_getxattr(struct dentry *dentry, const char *name,
1076 void *data, size_t size)
1078 struct gfs2_ea_request er;
1080 memset(&er, 0, sizeof(struct gfs2_ea_request));
1081 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1082 if (er.er_type == GFS2_EATYPE_UNUSED)
1085 er.er_name_len = strlen(er.er_name);
1086 er.er_data_len = size;
1088 return gfs2_ea_get(GFS2_I(dentry->d_inode), &er);
1091 static ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size)
1093 struct gfs2_ea_request er;
1095 memset(&er, 0, sizeof(struct gfs2_ea_request));
1096 er.er_data = (size) ? buffer : NULL;
1097 er.er_data_len = size;
1099 return gfs2_ea_list(GFS2_I(dentry->d_inode), &er);
1102 static int gfs2_removexattr(struct dentry *dentry, const char *name)
1104 struct gfs2_ea_request er;
1106 memset(&er, 0, sizeof(struct gfs2_ea_request));
1107 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1108 if (er.er_type == GFS2_EATYPE_UNUSED)
1110 er.er_name_len = strlen(er.er_name);
1112 return gfs2_ea_remove(GFS2_I(dentry->d_inode), &er);
1115 const struct inode_operations gfs2_file_iops = {
1116 .permission = gfs2_permission,
1117 .setattr = gfs2_setattr,
1118 .getattr = gfs2_getattr,
1119 .setxattr = gfs2_setxattr,
1120 .getxattr = gfs2_getxattr,
1121 .listxattr = gfs2_listxattr,
1122 .removexattr = gfs2_removexattr,
1125 const struct inode_operations gfs2_dev_iops = {
1126 .permission = gfs2_permission,
1127 .setattr = gfs2_setattr,
1128 .getattr = gfs2_getattr,
1129 .setxattr = gfs2_setxattr,
1130 .getxattr = gfs2_getxattr,
1131 .listxattr = gfs2_listxattr,
1132 .removexattr = gfs2_removexattr,
1135 const struct inode_operations gfs2_dir_iops = {
1136 .create = gfs2_create,
1137 .lookup = gfs2_lookup,
1139 .unlink = gfs2_unlink,
1140 .symlink = gfs2_symlink,
1141 .mkdir = gfs2_mkdir,
1142 .rmdir = gfs2_rmdir,
1143 .mknod = gfs2_mknod,
1144 .rename = gfs2_rename,
1145 .permission = gfs2_permission,
1146 .setattr = gfs2_setattr,
1147 .getattr = gfs2_getattr,
1148 .setxattr = gfs2_setxattr,
1149 .getxattr = gfs2_getxattr,
1150 .listxattr = gfs2_listxattr,
1151 .removexattr = gfs2_removexattr,
1154 const struct inode_operations gfs2_symlink_iops = {
1155 .readlink = gfs2_readlink,
1156 .follow_link = gfs2_follow_link,
1157 .permission = gfs2_permission,
1158 .setattr = gfs2_setattr,
1159 .getattr = gfs2_getattr,
1160 .setxattr = gfs2_setxattr,
1161 .getxattr = gfs2_getxattr,
1162 .listxattr = gfs2_listxattr,
1163 .removexattr = gfs2_removexattr,