2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2005 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 v.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 <asm/semaphore.h>
22 #include <asm/uaccess.h>
25 #include "lm_interface.h"
35 #include "ops_dentry.h"
36 #include "ops_inode.h"
45 * gfs2_create - Create a file
46 * @dir: The directory in which to create the file
47 * @dentry: The dentry of the new file
48 * @mode: The mode of the new file
53 static int gfs2_create(struct inode *dir, struct dentry *dentry,
54 int mode, struct nameidata *nd)
56 struct gfs2_inode *dip = dir->u.generic_ip;
57 struct gfs2_sbd *sdp = dip->i_sbd;
58 struct gfs2_holder ghs[2];
63 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
66 inode = gfs2_createi(ghs, &dentry->d_name, S_IFREG | mode);
69 if (dip->i_alloc.al_rgd)
70 gfs2_inplace_release(dip);
71 gfs2_quota_unlock(dip);
73 gfs2_glock_dq_uninit_m(2, ghs);
75 } else if (PTR_ERR(inode) != -EEXIST ||
76 (nd->intent.open.flags & O_EXCL)) {
77 gfs2_holder_uninit(ghs);
78 return PTR_ERR(inode);
81 error = gfs2_lookupi(dir, &dentry->d_name, 0, &inode);
84 gfs2_holder_uninit(ghs);
86 } else if (error != -ENOENT) {
87 gfs2_holder_uninit(ghs);
92 d_instantiate(dentry, inode);
94 mark_inode_dirty(inode);
100 * gfs2_lookup - Look up a filename in a directory and return its inode
101 * @dir: The directory inode
102 * @dentry: The dentry of the new inode
103 * @nd: passed from Linux VFS, ignored by us
105 * Called by the VFS layer. Lock dir and call gfs2_lookupi()
110 static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry,
111 struct nameidata *nd)
113 struct gfs2_inode *dip = dir->u.generic_ip;
114 struct gfs2_sbd *sdp = dip->i_sbd;
115 struct inode *inode = NULL;
118 if (!sdp->sd_args.ar_localcaching)
119 dentry->d_op = &gfs2_dops;
121 error = gfs2_lookupi(dir, &dentry->d_name, 0, &inode);
122 if (error && error != -ENOENT)
123 return ERR_PTR(error);
126 return d_splice_alias(inode, dentry);
127 d_add(dentry, inode);
133 * gfs2_link - Link to a file
134 * @old_dentry: The inode to link
135 * @dir: Add link to this directory
136 * @dentry: The name of the link
138 * Link the inode in "old_dentry" into the directory "dir" with the
144 static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
145 struct dentry *dentry)
147 struct gfs2_inode *dip = dir->u.generic_ip;
148 struct gfs2_sbd *sdp = dip->i_sbd;
149 struct inode *inode = old_dentry->d_inode;
150 struct gfs2_inode *ip = inode->u.generic_ip;
151 struct gfs2_holder ghs[2];
155 if (S_ISDIR(ip->i_di.di_mode))
158 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
159 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
161 error = gfs2_glock_nq_m(2, ghs);
165 error = gfs2_repermission(dir, MAY_WRITE | MAY_EXEC, NULL);
169 error = gfs2_dir_search(dip, &dentry->d_name, NULL, NULL);
180 if (!dip->i_di.di_nlink)
183 if (dip->i_di.di_entries == (uint32_t)-1)
186 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
189 if (!ip->i_di.di_nlink)
192 if (ip->i_di.di_nlink == (uint32_t)-1)
195 error = gfs2_diradd_alloc_required(dip, &dentry->d_name,
200 if (alloc_required) {
201 struct gfs2_alloc *al = gfs2_alloc_get(dip);
203 error = gfs2_quota_lock(dip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
207 error = gfs2_quota_check(dip, dip->i_di.di_uid,
212 al->al_requested = sdp->sd_max_dirres;
214 error = gfs2_inplace_reserve(dip);
218 error = gfs2_trans_begin(sdp,
220 al->al_rgd->rd_ri.ri_length +
221 2 * RES_DINODE + RES_STATFS +
226 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + RES_LEAF, 0);
231 error = gfs2_dir_add(dip, &dentry->d_name, &ip->i_num,
232 IF2DT(ip->i_di.di_mode));
236 error = gfs2_change_nlink(ip, +1);
243 gfs2_inplace_release(dip);
247 gfs2_quota_unlock(dip);
254 gfs2_glock_dq_m(2, ghs);
257 gfs2_holder_uninit(ghs);
258 gfs2_holder_uninit(ghs + 1);
261 atomic_inc(&inode->i_count);
262 d_instantiate(dentry, inode);
263 mark_inode_dirty(inode);
270 * gfs2_unlink - Unlink a file
271 * @dir: The inode of the directory containing the file to unlink
272 * @dentry: The file itself
274 * Unlink a file. Call gfs2_unlinki()
279 static int gfs2_unlink(struct inode *dir, struct dentry *dentry)
281 struct gfs2_inode *dip = dir->u.generic_ip;
282 struct gfs2_sbd *sdp = dip->i_sbd;
283 struct gfs2_inode *ip = dentry->d_inode->u.generic_ip;
284 struct gfs2_unlinked *ul;
285 struct gfs2_holder ghs[2];
288 error = gfs2_unlinked_get(sdp, &ul);
292 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
293 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
295 error = gfs2_glock_nq_m(2, ghs);
299 error = gfs2_unlink_ok(dip, &dentry->d_name, ip);
303 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + RES_LEAF +
308 error = gfs2_unlinki(dip, &dentry->d_name, ip,ul);
313 gfs2_glock_dq_m(2, ghs);
316 gfs2_holder_uninit(ghs);
317 gfs2_holder_uninit(ghs + 1);
319 gfs2_unlinked_put(sdp, ul);
325 * gfs2_symlink - Create a symlink
326 * @dir: The directory to create the symlink in
327 * @dentry: The dentry to put the symlink in
328 * @symname: The thing which the link points to
333 static int gfs2_symlink(struct inode *dir, struct dentry *dentry,
336 struct gfs2_inode *dip = dir->u.generic_ip, *ip;
337 struct gfs2_sbd *sdp = dip->i_sbd;
338 struct gfs2_holder ghs[2];
340 struct buffer_head *dibh;
344 /* Must be stuffed with a null terminator for gfs2_follow_link() */
345 size = strlen(symname);
346 if (size > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode) - 1)
347 return -ENAMETOOLONG;
349 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
351 inode = gfs2_createi(ghs, &dentry->d_name, S_IFLNK | S_IRWXUGO);
353 gfs2_holder_uninit(ghs);
354 return PTR_ERR(inode);
357 ip = ghs[1].gh_gl->gl_object;
359 ip->i_di.di_size = size;
361 error = gfs2_meta_inode_buffer(ip, &dibh);
363 if (!gfs2_assert_withdraw(sdp, !error)) {
364 gfs2_dinode_out(&ip->i_di, dibh->b_data);
365 memcpy(dibh->b_data + sizeof(struct gfs2_dinode), symname,
371 if (dip->i_alloc.al_rgd)
372 gfs2_inplace_release(dip);
373 gfs2_quota_unlock(dip);
376 gfs2_glock_dq_uninit_m(2, ghs);
378 d_instantiate(dentry, inode);
379 mark_inode_dirty(inode);
385 * gfs2_mkdir - Make a directory
386 * @dir: The parent directory of the new one
387 * @dentry: The dentry of the new directory
388 * @mode: The mode of the new directory
393 static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode)
395 struct gfs2_inode *dip = dir->u.generic_ip, *ip;
396 struct gfs2_sbd *sdp = dip->i_sbd;
397 struct gfs2_holder ghs[2];
399 struct buffer_head *dibh;
402 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
404 inode = gfs2_createi(ghs, &dentry->d_name, S_IFDIR | mode);
406 gfs2_holder_uninit(ghs);
407 return PTR_ERR(inode);
410 ip = ghs[1].gh_gl->gl_object;
412 ip->i_di.di_nlink = 2;
413 ip->i_di.di_size = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode);
414 ip->i_di.di_flags |= GFS2_DIF_JDATA;
415 ip->i_di.di_payload_format = GFS2_FORMAT_DE;
416 ip->i_di.di_entries = 2;
418 error = gfs2_meta_inode_buffer(ip, &dibh);
420 if (!gfs2_assert_withdraw(sdp, !error)) {
421 struct gfs2_dinode *di = (struct gfs2_dinode *)dibh->b_data;
422 struct gfs2_dirent *dent;
424 gfs2_dirent_alloc(ip, dibh, 1, &dent);
426 dent->de_inum = di->di_num; /* already GFS2 endian */
427 dent->de_hash = gfs2_disk_hash(".", 1);
428 dent->de_hash = cpu_to_be32(dent->de_hash);
429 dent->de_type = DT_DIR;
430 memcpy((char *) (dent + 1), ".", 1);
431 di->di_entries = cpu_to_be32(1);
433 gfs2_dirent_alloc(ip, dibh, 2, &dent);
435 gfs2_inum_out(&dip->i_num, (char *) &dent->de_inum);
436 dent->de_hash = gfs2_disk_hash("..", 2);
437 dent->de_hash = cpu_to_be32(dent->de_hash);
438 dent->de_type = DT_DIR;
439 memcpy((char *) (dent + 1), "..", 2);
441 gfs2_dinode_out(&ip->i_di, (char *)di);
446 error = gfs2_change_nlink(dip, +1);
447 gfs2_assert_withdraw(sdp, !error); /* dip already pinned */
450 if (dip->i_alloc.al_rgd)
451 gfs2_inplace_release(dip);
452 gfs2_quota_unlock(dip);
455 gfs2_glock_dq_uninit_m(2, ghs);
457 d_instantiate(dentry, inode);
458 mark_inode_dirty(inode);
464 * gfs2_rmdir - Remove a directory
465 * @dir: The parent directory of the directory to be removed
466 * @dentry: The dentry of the directory to remove
468 * Remove a directory. Call gfs2_rmdiri()
473 static int gfs2_rmdir(struct inode *dir, struct dentry *dentry)
475 struct gfs2_inode *dip = dir->u.generic_ip;
476 struct gfs2_sbd *sdp = dip->i_sbd;
477 struct gfs2_inode *ip = dentry->d_inode->u.generic_ip;
478 struct gfs2_unlinked *ul;
479 struct gfs2_holder ghs[2];
482 error = gfs2_unlinked_get(sdp, &ul);
486 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
487 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
489 error = gfs2_glock_nq_m(2, ghs);
493 error = gfs2_unlink_ok(dip, &dentry->d_name, ip);
497 if (ip->i_di.di_entries < 2) {
498 if (gfs2_consist_inode(ip))
499 gfs2_dinode_print(&ip->i_di);
503 if (ip->i_di.di_entries > 2) {
508 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + 3 * RES_LEAF +
513 error = gfs2_rmdiri(dip, &dentry->d_name, ip, ul);
518 gfs2_glock_dq_m(2, ghs);
521 gfs2_holder_uninit(ghs);
522 gfs2_holder_uninit(ghs + 1);
524 gfs2_unlinked_put(sdp, ul);
530 * gfs2_mknod - Make a special file
531 * @dir: The directory in which the special file will reside
532 * @dentry: The dentry of the special file
533 * @mode: The mode of the special file
534 * @rdev: The device specification of the special file
538 static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode,
541 struct gfs2_inode *dip = dir->u.generic_ip, *ip;
542 struct gfs2_sbd *sdp = dip->i_sbd;
543 struct gfs2_holder ghs[2];
545 struct buffer_head *dibh;
546 uint32_t major = 0, minor = 0;
549 switch (mode & S_IFMT) {
562 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
564 inode = gfs2_createi(ghs, &dentry->d_name, mode);
566 gfs2_holder_uninit(ghs);
567 return PTR_ERR(inode);
570 ip = ghs[1].gh_gl->gl_object;
572 ip->i_di.di_major = major;
573 ip->i_di.di_minor = minor;
575 error = gfs2_meta_inode_buffer(ip, &dibh);
577 if (!gfs2_assert_withdraw(sdp, !error)) {
578 gfs2_dinode_out(&ip->i_di, dibh->b_data);
583 if (dip->i_alloc.al_rgd)
584 gfs2_inplace_release(dip);
585 gfs2_quota_unlock(dip);
588 gfs2_glock_dq_uninit_m(2, ghs);
590 d_instantiate(dentry, inode);
591 mark_inode_dirty(inode);
597 * gfs2_rename - Rename a file
598 * @odir: Parent directory of old file name
599 * @odentry: The old dentry of the file
600 * @ndir: Parent directory of new file name
601 * @ndentry: The new dentry of the file
606 static int gfs2_rename(struct inode *odir, struct dentry *odentry,
607 struct inode *ndir, struct dentry *ndentry)
609 struct gfs2_inode *odip = odir->u.generic_ip;
610 struct gfs2_inode *ndip = ndir->u.generic_ip;
611 struct gfs2_inode *ip = odentry->d_inode->u.generic_ip;
612 struct gfs2_inode *nip = NULL;
613 struct gfs2_sbd *sdp = odip->i_sbd;
614 struct gfs2_unlinked *ul;
615 struct gfs2_holder ghs[4], r_gh;
622 if (ndentry->d_inode) {
623 nip = ndentry->d_inode->u.generic_ip;
628 error = gfs2_unlinked_get(sdp, &ul);
632 /* Make sure we aren't trying to move a dirctory into it's subdir */
634 if (S_ISDIR(ip->i_di.di_mode) && odip != ndip) {
637 error = gfs2_glock_nq_init(sdp->sd_rename_gl,
643 error = gfs2_ok_to_move(ip, ndip);
648 gfs2_holder_init(odip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
649 gfs2_holder_init(ndip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
650 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 2);
654 gfs2_holder_init(nip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh++);
656 error = gfs2_glock_nq_m(num_gh, ghs);
660 /* Check out the old directory */
662 error = gfs2_unlink_ok(odip, &odentry->d_name, ip);
666 /* Check out the new directory */
669 error = gfs2_unlink_ok(ndip, &ndentry->d_name, nip);
673 if (S_ISDIR(nip->i_di.di_mode)) {
674 if (nip->i_di.di_entries < 2) {
675 if (gfs2_consist_inode(nip))
676 gfs2_dinode_print(&nip->i_di);
680 if (nip->i_di.di_entries > 2) {
686 error = gfs2_repermission(ndir, MAY_WRITE | MAY_EXEC, NULL);
690 error = gfs2_dir_search(ndip, &ndentry->d_name, NULL, NULL);
702 if (!ndip->i_di.di_nlink) {
706 if (ndip->i_di.di_entries == (uint32_t)-1) {
710 if (S_ISDIR(ip->i_di.di_mode) &&
711 ndip->i_di.di_nlink == (uint32_t)-1) {
718 /* Check out the dir to be renamed */
721 error = gfs2_repermission(odentry->d_inode, MAY_WRITE, NULL);
726 error = gfs2_diradd_alloc_required(ndip, &ndentry->d_name,
731 if (alloc_required) {
732 struct gfs2_alloc *al = gfs2_alloc_get(ndip);
734 error = gfs2_quota_lock(ndip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
738 error = gfs2_quota_check(ndip, ndip->i_di.di_uid,
743 al->al_requested = sdp->sd_max_dirres;
745 error = gfs2_inplace_reserve(ndip);
749 error = gfs2_trans_begin(sdp,
751 al->al_rgd->rd_ri.ri_length +
752 4 * RES_DINODE + 4 * RES_LEAF +
753 RES_UNLINKED + RES_STATFS +
758 error = gfs2_trans_begin(sdp, 4 * RES_DINODE +
765 /* Remove the target file, if it exists */
768 if (S_ISDIR(nip->i_di.di_mode))
769 error = gfs2_rmdiri(ndip, &ndentry->d_name, nip, ul);
771 error = gfs2_unlinki(ndip, &ndentry->d_name, nip, ul);
781 error = gfs2_change_nlink(ndip, +1);
784 error = gfs2_change_nlink(odip, -1);
788 error = gfs2_dir_mvino(ip, &name, &ndip->i_num, DT_DIR);
792 struct buffer_head *dibh;
793 error = gfs2_meta_inode_buffer(ip, &dibh);
796 ip->i_di.di_ctime = get_seconds();
797 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
798 gfs2_dinode_out(&ip->i_di, dibh->b_data);
802 error = gfs2_dir_del(odip, &odentry->d_name);
806 error = gfs2_dir_add(ndip, &ndentry->d_name, &ip->i_num,
807 IF2DT(ip->i_di.di_mode));
816 gfs2_inplace_release(ndip);
820 gfs2_quota_unlock(ndip);
824 gfs2_alloc_put(ndip);
827 gfs2_glock_dq_m(num_gh, ghs);
830 for (x = 0; x < num_gh; x++)
831 gfs2_holder_uninit(ghs + x);
835 gfs2_glock_dq_uninit(&r_gh);
838 gfs2_unlinked_put(sdp, ul);
844 * gfs2_readlink - Read the value of a symlink
845 * @dentry: the symlink
846 * @buf: the buffer to read the symlink data into
847 * @size: the size of the buffer
852 static int gfs2_readlink(struct dentry *dentry, char __user *user_buf,
855 struct gfs2_inode *ip = dentry->d_inode->u.generic_ip;
856 char array[GFS2_FAST_NAME_SIZE], *buf = array;
857 unsigned int len = GFS2_FAST_NAME_SIZE;
860 error = gfs2_readlinki(ip, &buf, &len);
864 if (user_size > len - 1)
867 if (copy_to_user(user_buf, buf, user_size))
879 * gfs2_follow_link - Follow a symbolic link
880 * @dentry: The dentry of the link
881 * @nd: Data that we pass to vfs_follow_link()
883 * This can handle symlinks of any size. It is optimised for symlinks
884 * under GFS2_FAST_NAME_SIZE.
886 * Returns: 0 on success or error code
889 static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd)
891 struct gfs2_inode *ip = dentry->d_inode->u.generic_ip;
892 char array[GFS2_FAST_NAME_SIZE], *buf = array;
893 unsigned int len = GFS2_FAST_NAME_SIZE;
896 error = gfs2_readlinki(ip, &buf, &len);
898 error = vfs_follow_link(nd, buf);
903 return ERR_PTR(error);
910 * @nd: passed from Linux VFS, ignored by us
915 static int gfs2_permission(struct inode *inode, int mask, struct nameidata *nd)
917 struct gfs2_inode *ip = inode->u.generic_ip;
918 struct gfs2_holder i_gh;
921 if (ip->i_vn == ip->i_gl->gl_vn)
922 return generic_permission(inode, mask, gfs2_check_acl);
924 error = gfs2_glock_nq_init(ip->i_gl,
925 LM_ST_SHARED, LM_FLAG_ANY,
928 error = generic_permission(inode, mask, gfs2_check_acl_locked);
929 gfs2_glock_dq_uninit(&i_gh);
935 static int setattr_size(struct inode *inode, struct iattr *attr)
937 struct gfs2_inode *ip = inode->u.generic_ip;
940 if (attr->ia_size != ip->i_di.di_size) {
941 error = vmtruncate(inode, attr->ia_size);
946 error = gfs2_truncatei(ip, attr->ia_size);
953 static int setattr_chown(struct inode *inode, struct iattr *attr)
955 struct gfs2_inode *ip = inode->u.generic_ip;
956 struct gfs2_sbd *sdp = ip->i_sbd;
957 struct buffer_head *dibh;
958 uint32_t ouid, ogid, nuid, ngid;
961 ouid = ip->i_di.di_uid;
962 ogid = ip->i_di.di_gid;
966 if (!(attr->ia_valid & ATTR_UID) || ouid == nuid)
967 ouid = nuid = NO_QUOTA_CHANGE;
968 if (!(attr->ia_valid & ATTR_GID) || ogid == ngid)
969 ogid = ngid = NO_QUOTA_CHANGE;
973 error = gfs2_quota_lock(ip, nuid, ngid);
977 if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) {
978 error = gfs2_quota_check(ip, nuid, ngid);
983 error = gfs2_trans_begin(sdp, RES_DINODE + 2 * RES_QUOTA, 0);
987 error = gfs2_meta_inode_buffer(ip, &dibh);
991 error = inode_setattr(inode, attr);
992 gfs2_assert_warn(sdp, !error);
993 gfs2_inode_attr_out(ip);
995 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
996 gfs2_dinode_out(&ip->i_di, dibh->b_data);
999 if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) {
1000 gfs2_quota_change(ip, -ip->i_di.di_blocks,
1002 gfs2_quota_change(ip, ip->i_di.di_blocks,
1007 gfs2_trans_end(sdp);
1010 gfs2_quota_unlock(ip);
1019 * gfs2_setattr - Change attributes on an inode
1020 * @dentry: The dentry which is changing
1021 * @attr: The structure describing the change
1023 * The VFS layer wants to change one or more of an inodes attributes. Write
1024 * that change out to disk.
1029 static int gfs2_setattr(struct dentry *dentry, struct iattr *attr)
1031 struct inode *inode = dentry->d_inode;
1032 struct gfs2_inode *ip = inode->u.generic_ip;
1033 struct gfs2_holder i_gh;
1036 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh);
1041 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1044 error = inode_change_ok(inode, attr);
1048 if (attr->ia_valid & ATTR_SIZE)
1049 error = setattr_size(inode, attr);
1050 else if (attr->ia_valid & (ATTR_UID | ATTR_GID))
1051 error = setattr_chown(inode, attr);
1052 else if ((attr->ia_valid & ATTR_MODE) && IS_POSIXACL(inode))
1053 error = gfs2_acl_chmod(ip, attr);
1055 error = gfs2_setattr_simple(ip, attr);
1058 gfs2_glock_dq_uninit(&i_gh);
1061 mark_inode_dirty(inode);
1067 * gfs2_getattr - Read out an inode's attributes
1069 * @dentry: The dentry to stat
1070 * @stat: The inode's stats
1075 static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry,
1078 struct inode *inode = dentry->d_inode;
1079 struct gfs2_inode *ip = inode->u.generic_ip;
1080 struct gfs2_holder gh;
1083 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
1085 generic_fillattr(inode, stat);
1086 gfs2_glock_dq_uninit(&gh);
1092 static int gfs2_setxattr(struct dentry *dentry, const char *name,
1093 const void *data, size_t size, int flags)
1095 struct gfs2_inode *ip = dentry->d_inode->u.generic_ip;
1096 struct gfs2_ea_request er;
1098 memset(&er, 0, sizeof(struct gfs2_ea_request));
1099 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1100 if (er.er_type == GFS2_EATYPE_UNUSED)
1102 er.er_data = (char *)data;
1103 er.er_name_len = strlen(er.er_name);
1104 er.er_data_len = size;
1105 er.er_flags = flags;
1107 gfs2_assert_warn(ip->i_sbd, !(er.er_flags & GFS2_ERF_MODE));
1109 return gfs2_ea_set(ip, &er);
1112 static ssize_t gfs2_getxattr(struct dentry *dentry, const char *name,
1113 void *data, size_t size)
1115 struct gfs2_ea_request er;
1117 memset(&er, 0, sizeof(struct gfs2_ea_request));
1118 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1119 if (er.er_type == GFS2_EATYPE_UNUSED)
1122 er.er_name_len = strlen(er.er_name);
1123 er.er_data_len = size;
1125 return gfs2_ea_get(dentry->d_inode->u.generic_ip, &er);
1128 static ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size)
1130 struct gfs2_ea_request er;
1132 memset(&er, 0, sizeof(struct gfs2_ea_request));
1133 er.er_data = (size) ? buffer : NULL;
1134 er.er_data_len = size;
1136 return gfs2_ea_list(dentry->d_inode->u.generic_ip, &er);
1139 static int gfs2_removexattr(struct dentry *dentry, const char *name)
1141 struct gfs2_ea_request er;
1143 memset(&er, 0, sizeof(struct gfs2_ea_request));
1144 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1145 if (er.er_type == GFS2_EATYPE_UNUSED)
1147 er.er_name_len = strlen(er.er_name);
1149 return gfs2_ea_remove(dentry->d_inode->u.generic_ip, &er);
1152 struct inode_operations gfs2_file_iops = {
1153 .permission = gfs2_permission,
1154 .setattr = gfs2_setattr,
1155 .getattr = gfs2_getattr,
1156 .setxattr = gfs2_setxattr,
1157 .getxattr = gfs2_getxattr,
1158 .listxattr = gfs2_listxattr,
1159 .removexattr = gfs2_removexattr,
1162 struct inode_operations gfs2_dev_iops = {
1163 .permission = gfs2_permission,
1164 .setattr = gfs2_setattr,
1165 .getattr = gfs2_getattr,
1166 .setxattr = gfs2_setxattr,
1167 .getxattr = gfs2_getxattr,
1168 .listxattr = gfs2_listxattr,
1169 .removexattr = gfs2_removexattr,
1172 struct inode_operations gfs2_dir_iops = {
1173 .create = gfs2_create,
1174 .lookup = gfs2_lookup,
1176 .unlink = gfs2_unlink,
1177 .symlink = gfs2_symlink,
1178 .mkdir = gfs2_mkdir,
1179 .rmdir = gfs2_rmdir,
1180 .mknod = gfs2_mknod,
1181 .rename = gfs2_rename,
1182 .permission = gfs2_permission,
1183 .setattr = gfs2_setattr,
1184 .getattr = gfs2_getattr,
1185 .setxattr = gfs2_setxattr,
1186 .getxattr = gfs2_getxattr,
1187 .listxattr = gfs2_listxattr,
1188 .removexattr = gfs2_removexattr,
1191 struct inode_operations gfs2_symlink_iops = {
1192 .readlink = gfs2_readlink,
1193 .follow_link = gfs2_follow_link,
1194 .permission = gfs2_permission,
1195 .setattr = gfs2_setattr,
1196 .getattr = gfs2_getattr,
1197 .setxattr = gfs2_setxattr,
1198 .getxattr = gfs2_getxattr,
1199 .listxattr = gfs2_listxattr,
1200 .removexattr = gfs2_removexattr,