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 && (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_CAST(inode);
117 struct gfs2_glock *gl = GFS2_I(inode)->i_gl;
118 struct gfs2_holder gh;
120 error = gfs2_glock_nq_init(gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
123 return ERR_PTR(error);
125 gfs2_glock_dq_uninit(&gh);
126 return d_splice_alias(inode, dentry);
128 d_add(dentry, inode);
134 * gfs2_link - Link to a file
135 * @old_dentry: The inode to link
136 * @dir: Add link to this directory
137 * @dentry: The name of the link
139 * Link the inode in "old_dentry" into the directory "dir" with the
145 static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
146 struct dentry *dentry)
148 struct gfs2_inode *dip = GFS2_I(dir);
149 struct gfs2_sbd *sdp = GFS2_SB(dir);
150 struct inode *inode = old_dentry->d_inode;
151 struct gfs2_inode *ip = GFS2_I(inode);
152 struct gfs2_holder ghs[2];
156 if (S_ISDIR(inode->i_mode))
159 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
160 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
162 error = gfs2_glock_nq_m(2, ghs);
166 error = permission(dir, MAY_WRITE | MAY_EXEC, NULL);
170 error = gfs2_dir_check(dir, &dentry->d_name, NULL);
181 if (!dip->i_inode.i_nlink)
184 if (dip->i_di.di_entries == (u32)-1)
187 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
190 if (!ip->i_inode.i_nlink)
193 if (ip->i_inode.i_nlink == (u32)-1)
196 alloc_required = error = gfs2_diradd_alloc_required(dir, &dentry->d_name);
201 if (alloc_required) {
202 struct gfs2_alloc *al = gfs2_alloc_get(dip);
208 error = gfs2_quota_lock(dip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
212 error = gfs2_quota_check(dip, dip->i_inode.i_uid, dip->i_inode.i_gid);
216 al->al_requested = sdp->sd_max_dirres;
218 error = gfs2_inplace_reserve(dip);
222 error = gfs2_trans_begin(sdp, sdp->sd_max_dirres +
223 al->al_rgd->rd_length +
224 2 * RES_DINODE + RES_STATFS +
229 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + RES_LEAF, 0);
234 error = gfs2_dir_add(dir, &dentry->d_name, ip, IF2DT(inode->i_mode));
238 error = gfs2_change_nlink(ip, +1);
244 gfs2_inplace_release(dip);
247 gfs2_quota_unlock(dip);
252 gfs2_glock_dq_m(2, ghs);
254 gfs2_holder_uninit(ghs);
255 gfs2_holder_uninit(ghs + 1);
257 atomic_inc(&inode->i_count);
258 d_instantiate(dentry, inode);
259 mark_inode_dirty(inode);
265 * gfs2_unlink - Unlink a file
266 * @dir: The inode of the directory containing the file to unlink
267 * @dentry: The file itself
269 * Unlink a file. Call gfs2_unlinki()
274 static int gfs2_unlink(struct inode *dir, struct dentry *dentry)
276 struct gfs2_inode *dip = GFS2_I(dir);
277 struct gfs2_sbd *sdp = GFS2_SB(dir);
278 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
279 struct gfs2_holder ghs[3];
280 struct gfs2_rgrpd *rgd;
281 struct gfs2_holder ri_gh;
284 error = gfs2_rindex_hold(sdp, &ri_gh);
288 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
289 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
291 rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr);
292 gfs2_holder_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + 2);
295 error = gfs2_glock_nq(ghs); /* parent */
299 error = gfs2_glock_nq(ghs + 1); /* child */
303 error = gfs2_glock_nq(ghs + 2); /* rgrp */
307 error = gfs2_unlink_ok(dip, &dentry->d_name, ip);
311 error = gfs2_trans_begin(sdp, 2*RES_DINODE + RES_LEAF + RES_RG_BIT, 0);
315 error = gfs2_dir_del(dip, &dentry->d_name);
319 error = gfs2_change_nlink(ip, -1);
323 gfs2_glock_dq(ghs + 2);
325 gfs2_holder_uninit(ghs + 2);
326 gfs2_glock_dq(ghs + 1);
328 gfs2_holder_uninit(ghs + 1);
331 gfs2_holder_uninit(ghs);
332 gfs2_glock_dq_uninit(&ri_gh);
337 * gfs2_symlink - Create a symlink
338 * @dir: The directory to create the symlink in
339 * @dentry: The dentry to put the symlink in
340 * @symname: The thing which the link points to
345 static int gfs2_symlink(struct inode *dir, struct dentry *dentry,
348 struct gfs2_inode *dip = GFS2_I(dir), *ip;
349 struct gfs2_sbd *sdp = GFS2_SB(dir);
350 struct gfs2_holder ghs[2];
352 struct buffer_head *dibh;
356 /* Must be stuffed with a null terminator for gfs2_follow_link() */
357 size = strlen(symname);
358 if (size > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode) - 1)
359 return -ENAMETOOLONG;
361 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
363 inode = gfs2_createi(ghs, &dentry->d_name, S_IFLNK | S_IRWXUGO, 0);
365 gfs2_holder_uninit(ghs);
366 return PTR_ERR(inode);
369 ip = ghs[1].gh_gl->gl_object;
371 ip->i_di.di_size = size;
373 error = gfs2_meta_inode_buffer(ip, &dibh);
375 if (!gfs2_assert_withdraw(sdp, !error)) {
376 gfs2_dinode_out(ip, dibh->b_data);
377 memcpy(dibh->b_data + sizeof(struct gfs2_dinode), symname,
383 if (dip->i_alloc->al_rgd)
384 gfs2_inplace_release(dip);
385 gfs2_quota_unlock(dip);
388 gfs2_glock_dq_uninit_m(2, ghs);
390 d_instantiate(dentry, inode);
391 mark_inode_dirty(inode);
397 * gfs2_mkdir - Make a directory
398 * @dir: The parent directory of the new one
399 * @dentry: The dentry of the new directory
400 * @mode: The mode of the new directory
405 static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode)
407 struct gfs2_inode *dip = GFS2_I(dir), *ip;
408 struct gfs2_sbd *sdp = GFS2_SB(dir);
409 struct gfs2_holder ghs[2];
411 struct buffer_head *dibh;
414 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
416 inode = gfs2_createi(ghs, &dentry->d_name, S_IFDIR | mode, 0);
418 gfs2_holder_uninit(ghs);
419 return PTR_ERR(inode);
422 ip = ghs[1].gh_gl->gl_object;
424 ip->i_inode.i_nlink = 2;
425 ip->i_di.di_size = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode);
426 ip->i_di.di_flags |= GFS2_DIF_JDATA;
427 ip->i_di.di_entries = 2;
429 error = gfs2_meta_inode_buffer(ip, &dibh);
431 if (!gfs2_assert_withdraw(sdp, !error)) {
432 struct gfs2_dinode *di = (struct gfs2_dinode *)dibh->b_data;
433 struct gfs2_dirent *dent = (struct gfs2_dirent *)(di+1);
436 gfs2_str2qstr(&str, ".");
437 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
438 gfs2_qstr2dirent(&str, GFS2_DIRENT_SIZE(str.len), dent);
439 dent->de_inum = di->di_num; /* already GFS2 endian */
440 dent->de_type = cpu_to_be16(DT_DIR);
441 di->di_entries = cpu_to_be32(1);
443 gfs2_str2qstr(&str, "..");
444 dent = (struct gfs2_dirent *)((char*)dent + GFS2_DIRENT_SIZE(1));
445 gfs2_qstr2dirent(&str, dibh->b_size - GFS2_DIRENT_SIZE(1) - sizeof(struct gfs2_dinode), dent);
447 gfs2_inum_out(dip, dent);
448 dent->de_type = cpu_to_be16(DT_DIR);
450 gfs2_dinode_out(ip, di);
455 error = gfs2_change_nlink(dip, +1);
456 gfs2_assert_withdraw(sdp, !error); /* dip already pinned */
459 if (dip->i_alloc->al_rgd)
460 gfs2_inplace_release(dip);
461 gfs2_quota_unlock(dip);
464 gfs2_glock_dq_uninit_m(2, ghs);
466 d_instantiate(dentry, inode);
467 mark_inode_dirty(inode);
473 * gfs2_rmdir - Remove a directory
474 * @dir: The parent directory of the directory to be removed
475 * @dentry: The dentry of the directory to remove
477 * Remove a directory. Call gfs2_rmdiri()
482 static int gfs2_rmdir(struct inode *dir, struct dentry *dentry)
484 struct gfs2_inode *dip = GFS2_I(dir);
485 struct gfs2_sbd *sdp = GFS2_SB(dir);
486 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
487 struct gfs2_holder ghs[3];
488 struct gfs2_rgrpd *rgd;
489 struct gfs2_holder ri_gh;
493 error = gfs2_rindex_hold(sdp, &ri_gh);
496 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
497 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
499 rgd = gfs2_blk2rgrpd(sdp, ip->i_no_addr);
500 gfs2_holder_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + 2);
502 error = gfs2_glock_nq_m(3, ghs);
506 error = gfs2_unlink_ok(dip, &dentry->d_name, ip);
510 if (ip->i_di.di_entries < 2) {
511 if (gfs2_consist_inode(ip))
512 gfs2_dinode_print(ip);
516 if (ip->i_di.di_entries > 2) {
521 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + 3 * RES_LEAF + RES_RG_BIT, 0);
525 error = gfs2_rmdiri(dip, &dentry->d_name, ip);
530 gfs2_glock_dq_m(3, ghs);
532 gfs2_holder_uninit(ghs);
533 gfs2_holder_uninit(ghs + 1);
534 gfs2_holder_uninit(ghs + 2);
535 gfs2_glock_dq_uninit(&ri_gh);
540 * gfs2_mknod - Make a special file
541 * @dir: The directory in which the special file will reside
542 * @dentry: The dentry of the special file
543 * @mode: The mode of the special file
544 * @rdev: The device specification of the special file
548 static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode,
551 struct gfs2_inode *dip = GFS2_I(dir);
552 struct gfs2_sbd *sdp = GFS2_SB(dir);
553 struct gfs2_holder ghs[2];
556 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
558 inode = gfs2_createi(ghs, &dentry->d_name, mode, dev);
560 gfs2_holder_uninit(ghs);
561 return PTR_ERR(inode);
565 if (dip->i_alloc->al_rgd)
566 gfs2_inplace_release(dip);
567 gfs2_quota_unlock(dip);
570 gfs2_glock_dq_uninit_m(2, ghs);
572 d_instantiate(dentry, inode);
573 mark_inode_dirty(inode);
579 * gfs2_rename - Rename a file
580 * @odir: Parent directory of old file name
581 * @odentry: The old dentry of the file
582 * @ndir: Parent directory of new file name
583 * @ndentry: The new dentry of the file
588 static int gfs2_rename(struct inode *odir, struct dentry *odentry,
589 struct inode *ndir, struct dentry *ndentry)
591 struct gfs2_inode *odip = GFS2_I(odir);
592 struct gfs2_inode *ndip = GFS2_I(ndir);
593 struct gfs2_inode *ip = GFS2_I(odentry->d_inode);
594 struct gfs2_inode *nip = NULL;
595 struct gfs2_sbd *sdp = GFS2_SB(odir);
596 struct gfs2_holder ghs[5], r_gh;
597 struct gfs2_rgrpd *nrgd;
604 if (ndentry->d_inode) {
605 nip = GFS2_I(ndentry->d_inode);
610 /* Make sure we aren't trying to move a dirctory into it's subdir */
612 if (S_ISDIR(ip->i_inode.i_mode) && odip != ndip) {
615 error = gfs2_glock_nq_init(sdp->sd_rename_gl, LM_ST_EXCLUSIVE, 0,
620 error = gfs2_ok_to_move(ip, ndip);
626 gfs2_holder_init(odip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
628 gfs2_holder_init(ndip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
631 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
635 gfs2_holder_init(nip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
637 /* grab the resource lock for unlink flag twiddling
638 * this is the case of the target file already existing
639 * so we unlink before doing the rename
641 nrgd = gfs2_blk2rgrpd(sdp, nip->i_no_addr);
643 gfs2_holder_init(nrgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh++);
646 error = gfs2_glock_nq_m(num_gh, ghs);
650 /* Check out the old directory */
652 error = gfs2_unlink_ok(odip, &odentry->d_name, ip);
656 /* Check out the new directory */
659 error = gfs2_unlink_ok(ndip, &ndentry->d_name, nip);
663 if (S_ISDIR(nip->i_inode.i_mode)) {
664 if (nip->i_di.di_entries < 2) {
665 if (gfs2_consist_inode(nip))
666 gfs2_dinode_print(nip);
670 if (nip->i_di.di_entries > 2) {
676 error = permission(ndir, MAY_WRITE | MAY_EXEC, NULL);
680 error = gfs2_dir_check(ndir, &ndentry->d_name, NULL);
692 if (!ndip->i_inode.i_nlink) {
696 if (ndip->i_di.di_entries == (u32)-1) {
700 if (S_ISDIR(ip->i_inode.i_mode) &&
701 ndip->i_inode.i_nlink == (u32)-1) {
708 /* Check out the dir to be renamed */
711 error = permission(odentry->d_inode, MAY_WRITE, NULL);
716 alloc_required = error = gfs2_diradd_alloc_required(ndir, &ndentry->d_name);
721 if (alloc_required) {
722 struct gfs2_alloc *al = gfs2_alloc_get(ndip);
728 error = gfs2_quota_lock(ndip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
732 error = gfs2_quota_check(ndip, ndip->i_inode.i_uid, ndip->i_inode.i_gid);
736 al->al_requested = sdp->sd_max_dirres;
738 error = gfs2_inplace_reserve(ndip);
742 error = gfs2_trans_begin(sdp, sdp->sd_max_dirres +
743 al->al_rgd->rd_length +
744 4 * RES_DINODE + 4 * RES_LEAF +
745 RES_STATFS + RES_QUOTA + 4, 0);
749 error = gfs2_trans_begin(sdp, 4 * RES_DINODE +
750 5 * RES_LEAF + 4, 0);
755 /* Remove the target file, if it exists */
758 if (S_ISDIR(nip->i_inode.i_mode))
759 error = gfs2_rmdiri(ndip, &ndentry->d_name, nip);
761 error = gfs2_dir_del(ndip, &ndentry->d_name);
764 error = gfs2_change_nlink(nip, -1);
772 gfs2_str2qstr(&name, "..");
774 error = gfs2_change_nlink(ndip, +1);
777 error = gfs2_change_nlink(odip, -1);
781 error = gfs2_dir_mvino(ip, &name, ndip, DT_DIR);
785 struct buffer_head *dibh;
786 error = gfs2_meta_inode_buffer(ip, &dibh);
789 ip->i_inode.i_ctime = CURRENT_TIME;
790 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
791 gfs2_dinode_out(ip, dibh->b_data);
795 error = gfs2_dir_del(odip, &odentry->d_name);
799 error = gfs2_dir_add(ndir, &ndentry->d_name, ip, IF2DT(ip->i_inode.i_mode));
807 gfs2_inplace_release(ndip);
810 gfs2_quota_unlock(ndip);
813 gfs2_alloc_put(ndip);
815 gfs2_glock_dq_m(num_gh, ghs);
817 for (x = 0; x < num_gh; x++)
818 gfs2_holder_uninit(ghs + x);
821 gfs2_glock_dq_uninit(&r_gh);
827 * gfs2_readlink - Read the value of a symlink
828 * @dentry: the symlink
829 * @buf: the buffer to read the symlink data into
830 * @size: the size of the buffer
835 static int gfs2_readlink(struct dentry *dentry, char __user *user_buf,
838 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
839 char array[GFS2_FAST_NAME_SIZE], *buf = array;
840 unsigned int len = GFS2_FAST_NAME_SIZE;
843 error = gfs2_readlinki(ip, &buf, &len);
847 if (user_size > len - 1)
850 if (copy_to_user(user_buf, buf, user_size))
862 * gfs2_follow_link - Follow a symbolic link
863 * @dentry: The dentry of the link
864 * @nd: Data that we pass to vfs_follow_link()
866 * This can handle symlinks of any size. It is optimised for symlinks
867 * under GFS2_FAST_NAME_SIZE.
869 * Returns: 0 on success or error code
872 static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd)
874 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
875 char array[GFS2_FAST_NAME_SIZE], *buf = array;
876 unsigned int len = GFS2_FAST_NAME_SIZE;
879 error = gfs2_readlinki(ip, &buf, &len);
881 error = vfs_follow_link(nd, buf);
886 return ERR_PTR(error);
893 * @nd: passed from Linux VFS, ignored by us
895 * This may be called from the VFS directly, or from within GFS2 with the
896 * inode locked, so we look to see if the glock is already locked and only
897 * lock the glock if its not already been done.
902 static int gfs2_permission(struct inode *inode, int mask, struct nameidata *nd)
904 struct gfs2_inode *ip = GFS2_I(inode);
905 struct gfs2_holder i_gh;
909 if (gfs2_glock_is_locked_by_me(ip->i_gl) == NULL) {
910 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh);
916 error = generic_permission(inode, mask, gfs2_check_acl);
918 gfs2_glock_dq_uninit(&i_gh);
923 static int setattr_size(struct inode *inode, struct iattr *attr)
925 struct gfs2_inode *ip = GFS2_I(inode);
926 struct gfs2_sbd *sdp = GFS2_SB(inode);
929 if (attr->ia_size != ip->i_di.di_size) {
930 error = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks);
933 error = vmtruncate(inode, attr->ia_size);
939 error = gfs2_truncatei(ip, attr->ia_size);
940 if (error && (inode->i_size != ip->i_di.di_size))
941 i_size_write(inode, ip->i_di.di_size);
946 static int setattr_chown(struct inode *inode, struct iattr *attr)
948 struct gfs2_inode *ip = GFS2_I(inode);
949 struct gfs2_sbd *sdp = GFS2_SB(inode);
950 struct buffer_head *dibh;
951 u32 ouid, ogid, nuid, ngid;
959 if (!(attr->ia_valid & ATTR_UID) || ouid == nuid)
960 ouid = nuid = NO_QUOTA_CHANGE;
961 if (!(attr->ia_valid & ATTR_GID) || ogid == ngid)
962 ogid = ngid = NO_QUOTA_CHANGE;
964 if (!gfs2_alloc_get(ip))
967 error = gfs2_quota_lock(ip, nuid, ngid);
971 if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) {
972 error = gfs2_quota_check(ip, nuid, ngid);
977 error = gfs2_trans_begin(sdp, RES_DINODE + 2 * RES_QUOTA, 0);
981 error = gfs2_meta_inode_buffer(ip, &dibh);
985 error = inode_setattr(inode, attr);
986 gfs2_assert_warn(sdp, !error);
988 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
989 gfs2_dinode_out(ip, dibh->b_data);
992 if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) {
993 u64 blocks = gfs2_get_inode_blocks(&ip->i_inode);
994 gfs2_quota_change(ip, -blocks, ouid, ogid);
995 gfs2_quota_change(ip, blocks, nuid, ngid);
1001 gfs2_quota_unlock(ip);
1008 * gfs2_setattr - Change attributes on an inode
1009 * @dentry: The dentry which is changing
1010 * @attr: The structure describing the change
1012 * The VFS layer wants to change one or more of an inodes attributes. Write
1013 * that change out to disk.
1018 static int gfs2_setattr(struct dentry *dentry, struct iattr *attr)
1020 struct inode *inode = dentry->d_inode;
1021 struct gfs2_inode *ip = GFS2_I(inode);
1022 struct gfs2_holder i_gh;
1025 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh);
1030 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1033 error = inode_change_ok(inode, attr);
1037 if (attr->ia_valid & ATTR_SIZE)
1038 error = setattr_size(inode, attr);
1039 else if (attr->ia_valid & (ATTR_UID | ATTR_GID))
1040 error = setattr_chown(inode, attr);
1041 else if ((attr->ia_valid & ATTR_MODE) && IS_POSIXACL(inode))
1042 error = gfs2_acl_chmod(ip, attr);
1044 error = gfs2_setattr_simple(ip, attr);
1047 gfs2_glock_dq_uninit(&i_gh);
1049 mark_inode_dirty(inode);
1054 * gfs2_getattr - Read out an inode's attributes
1055 * @mnt: The vfsmount the inode is being accessed from
1056 * @dentry: The dentry to stat
1057 * @stat: The inode's stats
1059 * This may be called from the VFS directly, or from within GFS2 with the
1060 * inode locked, so we look to see if the glock is already locked and only
1061 * lock the glock if its not already been done. Note that its the NFS
1062 * readdirplus operation which causes this to be called (from filldir)
1063 * with the glock already held.
1068 static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry,
1071 struct inode *inode = dentry->d_inode;
1072 struct gfs2_inode *ip = GFS2_I(inode);
1073 struct gfs2_holder gh;
1077 if (gfs2_glock_is_locked_by_me(ip->i_gl) == NULL) {
1078 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
1084 generic_fillattr(inode, stat);
1086 gfs2_glock_dq_uninit(&gh);
1091 static int gfs2_setxattr(struct dentry *dentry, const char *name,
1092 const void *data, size_t size, int flags)
1094 struct inode *inode = dentry->d_inode;
1095 struct gfs2_ea_request er;
1097 memset(&er, 0, sizeof(struct gfs2_ea_request));
1098 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1099 if (er.er_type == GFS2_EATYPE_UNUSED)
1101 er.er_data = (char *)data;
1102 er.er_name_len = strlen(er.er_name);
1103 er.er_data_len = size;
1104 er.er_flags = flags;
1106 gfs2_assert_warn(GFS2_SB(inode), !(er.er_flags & GFS2_ERF_MODE));
1108 return gfs2_ea_set(GFS2_I(inode), &er);
1111 static ssize_t gfs2_getxattr(struct dentry *dentry, const char *name,
1112 void *data, size_t size)
1114 struct gfs2_ea_request er;
1116 memset(&er, 0, sizeof(struct gfs2_ea_request));
1117 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1118 if (er.er_type == GFS2_EATYPE_UNUSED)
1121 er.er_name_len = strlen(er.er_name);
1122 er.er_data_len = size;
1124 return gfs2_ea_get(GFS2_I(dentry->d_inode), &er);
1127 static ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size)
1129 struct gfs2_ea_request er;
1131 memset(&er, 0, sizeof(struct gfs2_ea_request));
1132 er.er_data = (size) ? buffer : NULL;
1133 er.er_data_len = size;
1135 return gfs2_ea_list(GFS2_I(dentry->d_inode), &er);
1138 static int gfs2_removexattr(struct dentry *dentry, const char *name)
1140 struct gfs2_ea_request er;
1142 memset(&er, 0, sizeof(struct gfs2_ea_request));
1143 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1144 if (er.er_type == GFS2_EATYPE_UNUSED)
1146 er.er_name_len = strlen(er.er_name);
1148 return gfs2_ea_remove(GFS2_I(dentry->d_inode), &er);
1151 const struct inode_operations gfs2_file_iops = {
1152 .permission = gfs2_permission,
1153 .setattr = gfs2_setattr,
1154 .getattr = gfs2_getattr,
1155 .setxattr = gfs2_setxattr,
1156 .getxattr = gfs2_getxattr,
1157 .listxattr = gfs2_listxattr,
1158 .removexattr = gfs2_removexattr,
1161 const struct inode_operations gfs2_dir_iops = {
1162 .create = gfs2_create,
1163 .lookup = gfs2_lookup,
1165 .unlink = gfs2_unlink,
1166 .symlink = gfs2_symlink,
1167 .mkdir = gfs2_mkdir,
1168 .rmdir = gfs2_rmdir,
1169 .mknod = gfs2_mknod,
1170 .rename = gfs2_rename,
1171 .permission = gfs2_permission,
1172 .setattr = gfs2_setattr,
1173 .getattr = gfs2_getattr,
1174 .setxattr = gfs2_setxattr,
1175 .getxattr = gfs2_getxattr,
1176 .listxattr = gfs2_listxattr,
1177 .removexattr = gfs2_removexattr,
1180 const struct inode_operations gfs2_symlink_iops = {
1181 .readlink = gfs2_readlink,
1182 .follow_link = gfs2_follow_link,
1183 .permission = gfs2_permission,
1184 .setattr = gfs2_setattr,
1185 .getattr = gfs2_getattr,
1186 .setxattr = gfs2_setxattr,
1187 .getxattr = gfs2_getxattr,
1188 .listxattr = gfs2_listxattr,
1189 .removexattr = gfs2_removexattr,