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 <linux/crc32.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];
62 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
65 inode = gfs2_createi(ghs, &dentry->d_name, S_IFREG | mode);
68 if (dip->i_alloc.al_rgd)
69 gfs2_inplace_release(dip);
70 gfs2_quota_unlock(dip);
72 gfs2_glock_dq_uninit_m(2, ghs);
74 } else if (PTR_ERR(inode) != -EEXIST ||
75 (nd->intent.open.flags & O_EXCL)) {
76 gfs2_holder_uninit(ghs);
77 return PTR_ERR(inode);
80 inode = gfs2_lookupi(dir, &dentry->d_name, 0, nd);
84 gfs2_holder_uninit(ghs);
87 gfs2_holder_uninit(ghs);
88 return PTR_ERR(inode);
93 d_instantiate(dentry, inode);
95 mark_inode_dirty(inode);
101 * gfs2_lookup - Look up a filename in a directory and return its inode
102 * @dir: The directory inode
103 * @dentry: The dentry of the new inode
104 * @nd: passed from Linux VFS, ignored by us
106 * Called by the VFS layer. Lock dir and call gfs2_lookupi()
111 static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry,
112 struct nameidata *nd)
114 struct inode *inode = NULL;
116 dentry->d_op = &gfs2_dops;
118 inode = gfs2_lookupi(dir, &dentry->d_name, 0, nd);
119 if (inode && IS_ERR(inode))
120 return ERR_PTR(PTR_ERR(inode));
123 return d_splice_alias(inode, dentry);
124 d_add(dentry, inode);
130 * gfs2_link - Link to a file
131 * @old_dentry: The inode to link
132 * @dir: Add link to this directory
133 * @dentry: The name of the link
135 * Link the inode in "old_dentry" into the directory "dir" with the
141 static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
142 struct dentry *dentry)
144 struct gfs2_inode *dip = dir->u.generic_ip;
145 struct gfs2_sbd *sdp = dip->i_sbd;
146 struct inode *inode = old_dentry->d_inode;
147 struct gfs2_inode *ip = inode->u.generic_ip;
148 struct gfs2_holder ghs[2];
152 if (S_ISDIR(ip->i_di.di_mode))
155 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
156 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
158 error = gfs2_glock_nq_m(2, ghs);
162 error = gfs2_repermission(dir, MAY_WRITE | MAY_EXEC, NULL);
166 error = gfs2_dir_search(dir, &dentry->d_name, NULL, NULL);
177 if (!dip->i_di.di_nlink)
180 if (dip->i_di.di_entries == (uint32_t)-1)
183 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
186 if (!ip->i_di.di_nlink)
189 if (ip->i_di.di_nlink == (uint32_t)-1)
192 alloc_required = error = gfs2_diradd_alloc_required(dir, &dentry->d_name);
197 if (alloc_required) {
198 struct gfs2_alloc *al = gfs2_alloc_get(dip);
200 error = gfs2_quota_lock(dip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
204 error = gfs2_quota_check(dip, dip->i_di.di_uid,
209 al->al_requested = sdp->sd_max_dirres;
211 error = gfs2_inplace_reserve(dip);
215 error = gfs2_trans_begin(sdp, sdp->sd_max_dirres +
216 al->al_rgd->rd_ri.ri_length +
217 2 * RES_DINODE + RES_STATFS +
222 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + RES_LEAF, 0);
227 error = gfs2_dir_add(dir, &dentry->d_name, &ip->i_num,
228 IF2DT(ip->i_di.di_mode));
232 error = gfs2_change_nlink(ip, +1);
239 gfs2_inplace_release(dip);
243 gfs2_quota_unlock(dip);
250 gfs2_glock_dq_m(2, ghs);
253 gfs2_holder_uninit(ghs);
254 gfs2_holder_uninit(ghs + 1);
257 atomic_inc(&inode->i_count);
258 d_instantiate(dentry, inode);
259 mark_inode_dirty(inode);
266 * gfs2_unlink - Unlink a file
267 * @dir: The inode of the directory containing the file to unlink
268 * @dentry: The file itself
270 * Unlink a file. Call gfs2_unlinki()
275 static int gfs2_unlink(struct inode *dir, struct dentry *dentry)
277 struct gfs2_inode *dip = dir->u.generic_ip;
278 struct gfs2_sbd *sdp = dip->i_sbd;
279 struct gfs2_inode *ip = dentry->d_inode->u.generic_ip;
280 struct gfs2_unlinked *ul;
281 struct gfs2_holder ghs[2];
284 error = gfs2_unlinked_get(sdp, &ul);
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 error = gfs2_glock_nq_m(2, ghs);
295 error = gfs2_unlink_ok(dip, &dentry->d_name, ip);
299 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + RES_LEAF +
304 error = gfs2_unlinki(dip, &dentry->d_name, ip, ul);
309 gfs2_glock_dq_m(2, ghs);
312 gfs2_holder_uninit(ghs);
313 gfs2_holder_uninit(ghs + 1);
315 gfs2_unlinked_put(sdp, ul);
321 * gfs2_symlink - Create a symlink
322 * @dir: The directory to create the symlink in
323 * @dentry: The dentry to put the symlink in
324 * @symname: The thing which the link points to
329 static int gfs2_symlink(struct inode *dir, struct dentry *dentry,
332 struct gfs2_inode *dip = dir->u.generic_ip, *ip;
333 struct gfs2_sbd *sdp = dip->i_sbd;
334 struct gfs2_holder ghs[2];
336 struct buffer_head *dibh;
340 /* Must be stuffed with a null terminator for gfs2_follow_link() */
341 size = strlen(symname);
342 if (size > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode) - 1)
343 return -ENAMETOOLONG;
345 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
347 inode = gfs2_createi(ghs, &dentry->d_name, S_IFLNK | S_IRWXUGO);
349 gfs2_holder_uninit(ghs);
350 return PTR_ERR(inode);
353 ip = ghs[1].gh_gl->gl_object;
355 ip->i_di.di_size = size;
357 error = gfs2_meta_inode_buffer(ip, &dibh);
359 if (!gfs2_assert_withdraw(sdp, !error)) {
360 gfs2_dinode_out(&ip->i_di, dibh->b_data);
361 memcpy(dibh->b_data + sizeof(struct gfs2_dinode), symname,
367 if (dip->i_alloc.al_rgd)
368 gfs2_inplace_release(dip);
369 gfs2_quota_unlock(dip);
372 gfs2_glock_dq_uninit_m(2, ghs);
374 d_instantiate(dentry, inode);
375 mark_inode_dirty(inode);
381 * gfs2_mkdir - Make a directory
382 * @dir: The parent directory of the new one
383 * @dentry: The dentry of the new directory
384 * @mode: The mode of the new directory
389 static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode)
391 struct gfs2_inode *dip = dir->u.generic_ip, *ip;
392 struct gfs2_sbd *sdp = dip->i_sbd;
393 struct gfs2_holder ghs[2];
395 struct buffer_head *dibh;
398 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
400 inode = gfs2_createi(ghs, &dentry->d_name, S_IFDIR | mode);
402 gfs2_holder_uninit(ghs);
403 return PTR_ERR(inode);
406 ip = ghs[1].gh_gl->gl_object;
408 ip->i_di.di_nlink = 2;
409 ip->i_di.di_size = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode);
410 ip->i_di.di_flags |= GFS2_DIF_JDATA;
411 ip->i_di.di_payload_format = GFS2_FORMAT_DE;
412 ip->i_di.di_entries = 2;
414 error = gfs2_meta_inode_buffer(ip, &dibh);
416 if (!gfs2_assert_withdraw(sdp, !error)) {
417 struct gfs2_dinode *di = (struct gfs2_dinode *)dibh->b_data;
418 struct gfs2_dirent *dent = (struct gfs2_dirent *)(di+1);
421 gfs2_str2qstr(&str, ".");
422 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
423 gfs2_qstr2dirent(&str, GFS2_DIRENT_SIZE(str.len), dent);
424 dent->de_inum = di->di_num; /* already GFS2 endian */
425 dent->de_type = DT_DIR;
426 di->di_entries = cpu_to_be32(1);
428 gfs2_str2qstr(&str, "..");
429 dent = (struct gfs2_dirent *)((char*)dent + GFS2_DIRENT_SIZE(1));
430 gfs2_qstr2dirent(&str, dibh->b_size - GFS2_DIRENT_SIZE(1) - sizeof(struct gfs2_dinode), dent);
432 gfs2_inum_out(&dip->i_num, (char *) &dent->de_inum);
433 dent->de_type = DT_DIR;
435 gfs2_dinode_out(&ip->i_di, (char *)di);
440 error = gfs2_change_nlink(dip, +1);
441 gfs2_assert_withdraw(sdp, !error); /* dip already pinned */
444 if (dip->i_alloc.al_rgd)
445 gfs2_inplace_release(dip);
446 gfs2_quota_unlock(dip);
449 gfs2_glock_dq_uninit_m(2, ghs);
451 d_instantiate(dentry, inode);
452 mark_inode_dirty(inode);
458 * gfs2_rmdir - Remove a directory
459 * @dir: The parent directory of the directory to be removed
460 * @dentry: The dentry of the directory to remove
462 * Remove a directory. Call gfs2_rmdiri()
467 static int gfs2_rmdir(struct inode *dir, struct dentry *dentry)
469 struct gfs2_inode *dip = dir->u.generic_ip;
470 struct gfs2_sbd *sdp = dip->i_sbd;
471 struct gfs2_inode *ip = dentry->d_inode->u.generic_ip;
472 struct gfs2_unlinked *ul;
473 struct gfs2_holder ghs[2];
476 error = gfs2_unlinked_get(sdp, &ul);
480 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
481 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
483 error = gfs2_glock_nq_m(2, ghs);
487 error = gfs2_unlink_ok(dip, &dentry->d_name, ip);
491 if (ip->i_di.di_entries < 2) {
492 if (gfs2_consist_inode(ip))
493 gfs2_dinode_print(&ip->i_di);
497 if (ip->i_di.di_entries > 2) {
502 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + 3 * RES_LEAF +
507 error = gfs2_rmdiri(dip, &dentry->d_name, ip, ul);
512 gfs2_glock_dq_m(2, ghs);
515 gfs2_holder_uninit(ghs);
516 gfs2_holder_uninit(ghs + 1);
518 gfs2_unlinked_put(sdp, ul);
524 * gfs2_mknod - Make a special file
525 * @dir: The directory in which the special file will reside
526 * @dentry: The dentry of the special file
527 * @mode: The mode of the special file
528 * @rdev: The device specification of the special file
532 static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode,
535 struct gfs2_inode *dip = dir->u.generic_ip, *ip;
536 struct gfs2_sbd *sdp = dip->i_sbd;
537 struct gfs2_holder ghs[2];
539 struct buffer_head *dibh;
540 uint32_t major = 0, minor = 0;
543 switch (mode & S_IFMT) {
556 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
558 inode = gfs2_createi(ghs, &dentry->d_name, mode);
560 gfs2_holder_uninit(ghs);
561 return PTR_ERR(inode);
564 ip = ghs[1].gh_gl->gl_object;
566 ip->i_di.di_major = major;
567 ip->i_di.di_minor = minor;
569 error = gfs2_meta_inode_buffer(ip, &dibh);
571 if (!gfs2_assert_withdraw(sdp, !error)) {
572 gfs2_dinode_out(&ip->i_di, dibh->b_data);
577 if (dip->i_alloc.al_rgd)
578 gfs2_inplace_release(dip);
579 gfs2_quota_unlock(dip);
582 gfs2_glock_dq_uninit_m(2, ghs);
584 d_instantiate(dentry, inode);
585 mark_inode_dirty(inode);
591 * gfs2_rename - Rename a file
592 * @odir: Parent directory of old file name
593 * @odentry: The old dentry of the file
594 * @ndir: Parent directory of new file name
595 * @ndentry: The new dentry of the file
600 static int gfs2_rename(struct inode *odir, struct dentry *odentry,
601 struct inode *ndir, struct dentry *ndentry)
603 struct gfs2_inode *odip = odir->u.generic_ip;
604 struct gfs2_inode *ndip = ndir->u.generic_ip;
605 struct gfs2_inode *ip = odentry->d_inode->u.generic_ip;
606 struct gfs2_inode *nip = NULL;
607 struct gfs2_sbd *sdp = odip->i_sbd;
608 struct gfs2_unlinked *ul;
609 struct gfs2_holder ghs[4], r_gh;
616 if (ndentry->d_inode) {
617 nip = ndentry->d_inode->u.generic_ip;
622 error = gfs2_unlinked_get(sdp, &ul);
626 /* Make sure we aren't trying to move a dirctory into it's subdir */
628 if (S_ISDIR(ip->i_di.di_mode) && odip != ndip) {
631 error = gfs2_glock_nq_init(sdp->sd_rename_gl,
637 error = gfs2_ok_to_move(ip, ndip);
642 gfs2_holder_init(odip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
643 gfs2_holder_init(ndip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
644 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 2);
648 gfs2_holder_init(nip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh++);
650 error = gfs2_glock_nq_m(num_gh, ghs);
654 /* Check out the old directory */
656 error = gfs2_unlink_ok(odip, &odentry->d_name, ip);
660 /* Check out the new directory */
663 error = gfs2_unlink_ok(ndip, &ndentry->d_name, nip);
667 if (S_ISDIR(nip->i_di.di_mode)) {
668 if (nip->i_di.di_entries < 2) {
669 if (gfs2_consist_inode(nip))
670 gfs2_dinode_print(&nip->i_di);
674 if (nip->i_di.di_entries > 2) {
680 error = gfs2_repermission(ndir, MAY_WRITE | MAY_EXEC, NULL);
684 error = gfs2_dir_search(ndir, &ndentry->d_name, NULL, NULL);
696 if (!ndip->i_di.di_nlink) {
700 if (ndip->i_di.di_entries == (uint32_t)-1) {
704 if (S_ISDIR(ip->i_di.di_mode) &&
705 ndip->i_di.di_nlink == (uint32_t)-1) {
712 /* Check out the dir to be renamed */
715 error = gfs2_repermission(odentry->d_inode, MAY_WRITE, NULL);
720 alloc_required = error = gfs2_diradd_alloc_required(ndir, &ndentry->d_name);
725 if (alloc_required) {
726 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_di.di_uid,
737 al->al_requested = sdp->sd_max_dirres;
739 error = gfs2_inplace_reserve(ndip);
743 error = gfs2_trans_begin(sdp, sdp->sd_max_dirres +
744 al->al_rgd->rd_ri.ri_length +
745 4 * RES_DINODE + 4 * RES_LEAF +
746 RES_UNLINKED + RES_STATFS +
751 error = gfs2_trans_begin(sdp, 4 * RES_DINODE +
758 /* Remove the target file, if it exists */
761 if (S_ISDIR(nip->i_di.di_mode))
762 error = gfs2_rmdiri(ndip, &ndentry->d_name, nip, ul);
764 error = gfs2_unlinki(ndip, &ndentry->d_name, nip, ul);
771 gfs2_str2qstr(&name, "..");
773 error = gfs2_change_nlink(ndip, +1);
776 error = gfs2_change_nlink(odip, -1);
780 error = gfs2_dir_mvino(ip, &name, &ndip->i_num, DT_DIR);
784 struct buffer_head *dibh;
785 error = gfs2_meta_inode_buffer(ip, &dibh);
788 ip->i_di.di_ctime = get_seconds();
789 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
790 gfs2_dinode_out(&ip->i_di, dibh->b_data);
794 error = gfs2_dir_del(odip, &odentry->d_name);
798 error = gfs2_dir_add(ndir, &ndentry->d_name, &ip->i_num,
799 IF2DT(ip->i_di.di_mode));
808 gfs2_inplace_release(ndip);
812 gfs2_quota_unlock(ndip);
816 gfs2_alloc_put(ndip);
819 gfs2_glock_dq_m(num_gh, ghs);
822 for (x = 0; x < num_gh; x++)
823 gfs2_holder_uninit(ghs + x);
827 gfs2_glock_dq_uninit(&r_gh);
830 gfs2_unlinked_put(sdp, ul);
836 * gfs2_readlink - Read the value of a symlink
837 * @dentry: the symlink
838 * @buf: the buffer to read the symlink data into
839 * @size: the size of the buffer
844 static int gfs2_readlink(struct dentry *dentry, char __user *user_buf,
847 struct gfs2_inode *ip = dentry->d_inode->u.generic_ip;
848 char array[GFS2_FAST_NAME_SIZE], *buf = array;
849 unsigned int len = GFS2_FAST_NAME_SIZE;
852 error = gfs2_readlinki(ip, &buf, &len);
856 if (user_size > len - 1)
859 if (copy_to_user(user_buf, buf, user_size))
871 * gfs2_follow_link - Follow a symbolic link
872 * @dentry: The dentry of the link
873 * @nd: Data that we pass to vfs_follow_link()
875 * This can handle symlinks of any size. It is optimised for symlinks
876 * under GFS2_FAST_NAME_SIZE.
878 * Returns: 0 on success or error code
881 static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd)
883 struct gfs2_inode *ip = dentry->d_inode->u.generic_ip;
884 char array[GFS2_FAST_NAME_SIZE], *buf = array;
885 unsigned int len = GFS2_FAST_NAME_SIZE;
888 error = gfs2_readlinki(ip, &buf, &len);
890 error = vfs_follow_link(nd, buf);
895 return ERR_PTR(error);
902 * @nd: passed from Linux VFS, ignored by us
907 static int gfs2_permission(struct inode *inode, int mask, struct nameidata *nd)
909 struct gfs2_inode *ip = inode->u.generic_ip;
910 struct gfs2_holder i_gh;
913 if (ip->i_vn == ip->i_gl->gl_vn)
914 return generic_permission(inode, mask, gfs2_check_acl);
916 error = gfs2_glock_nq_init(ip->i_gl,
917 LM_ST_SHARED, LM_FLAG_ANY,
920 error = generic_permission(inode, mask, gfs2_check_acl_locked);
921 gfs2_glock_dq_uninit(&i_gh);
927 static int setattr_size(struct inode *inode, struct iattr *attr)
929 struct gfs2_inode *ip = inode->u.generic_ip;
932 if (attr->ia_size != ip->i_di.di_size) {
933 error = vmtruncate(inode, attr->ia_size);
938 error = gfs2_truncatei(ip, attr->ia_size);
945 static int setattr_chown(struct inode *inode, struct iattr *attr)
947 struct gfs2_inode *ip = inode->u.generic_ip;
948 struct gfs2_sbd *sdp = ip->i_sbd;
949 struct buffer_head *dibh;
950 uint32_t ouid, ogid, nuid, ngid;
953 ouid = ip->i_di.di_uid;
954 ogid = ip->i_di.di_gid;
958 if (!(attr->ia_valid & ATTR_UID) || ouid == nuid)
959 ouid = nuid = NO_QUOTA_CHANGE;
960 if (!(attr->ia_valid & ATTR_GID) || ogid == ngid)
961 ogid = ngid = NO_QUOTA_CHANGE;
965 error = gfs2_quota_lock(ip, nuid, ngid);
969 if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) {
970 error = gfs2_quota_check(ip, nuid, ngid);
975 error = gfs2_trans_begin(sdp, RES_DINODE + 2 * RES_QUOTA, 0);
979 error = gfs2_meta_inode_buffer(ip, &dibh);
983 error = inode_setattr(inode, attr);
984 gfs2_assert_warn(sdp, !error);
985 gfs2_inode_attr_out(ip);
987 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
988 gfs2_dinode_out(&ip->i_di, dibh->b_data);
991 if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) {
992 gfs2_quota_change(ip, -ip->i_di.di_blocks,
994 gfs2_quota_change(ip, ip->i_di.di_blocks,
1002 gfs2_quota_unlock(ip);
1011 * gfs2_setattr - Change attributes on an inode
1012 * @dentry: The dentry which is changing
1013 * @attr: The structure describing the change
1015 * The VFS layer wants to change one or more of an inodes attributes. Write
1016 * that change out to disk.
1021 static int gfs2_setattr(struct dentry *dentry, struct iattr *attr)
1023 struct inode *inode = dentry->d_inode;
1024 struct gfs2_inode *ip = inode->u.generic_ip;
1025 struct gfs2_holder i_gh;
1028 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh);
1033 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1036 error = inode_change_ok(inode, attr);
1040 if (attr->ia_valid & ATTR_SIZE)
1041 error = setattr_size(inode, attr);
1042 else if (attr->ia_valid & (ATTR_UID | ATTR_GID))
1043 error = setattr_chown(inode, attr);
1044 else if ((attr->ia_valid & ATTR_MODE) && IS_POSIXACL(inode))
1045 error = gfs2_acl_chmod(ip, attr);
1047 error = gfs2_setattr_simple(ip, attr);
1050 gfs2_glock_dq_uninit(&i_gh);
1053 mark_inode_dirty(inode);
1059 * gfs2_getattr - Read out an inode's attributes
1061 * @dentry: The dentry to stat
1062 * @stat: The inode's stats
1067 static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry,
1070 struct inode *inode = dentry->d_inode;
1071 struct gfs2_inode *ip = inode->u.generic_ip;
1072 struct gfs2_holder gh;
1075 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
1077 generic_fillattr(inode, stat);
1078 gfs2_glock_dq_uninit(&gh);
1084 static int gfs2_setxattr(struct dentry *dentry, const char *name,
1085 const void *data, size_t size, int flags)
1087 struct gfs2_inode *ip = dentry->d_inode->u.generic_ip;
1088 struct gfs2_ea_request er;
1090 memset(&er, 0, sizeof(struct gfs2_ea_request));
1091 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1092 if (er.er_type == GFS2_EATYPE_UNUSED)
1094 er.er_data = (char *)data;
1095 er.er_name_len = strlen(er.er_name);
1096 er.er_data_len = size;
1097 er.er_flags = flags;
1099 gfs2_assert_warn(ip->i_sbd, !(er.er_flags & GFS2_ERF_MODE));
1101 return gfs2_ea_set(ip, &er);
1104 static ssize_t gfs2_getxattr(struct dentry *dentry, const char *name,
1105 void *data, size_t size)
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)
1114 er.er_name_len = strlen(er.er_name);
1115 er.er_data_len = size;
1117 return gfs2_ea_get(dentry->d_inode->u.generic_ip, &er);
1120 static ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size)
1122 struct gfs2_ea_request er;
1124 memset(&er, 0, sizeof(struct gfs2_ea_request));
1125 er.er_data = (size) ? buffer : NULL;
1126 er.er_data_len = size;
1128 return gfs2_ea_list(dentry->d_inode->u.generic_ip, &er);
1131 static int gfs2_removexattr(struct dentry *dentry, const char *name)
1133 struct gfs2_ea_request er;
1135 memset(&er, 0, sizeof(struct gfs2_ea_request));
1136 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1137 if (er.er_type == GFS2_EATYPE_UNUSED)
1139 er.er_name_len = strlen(er.er_name);
1141 return gfs2_ea_remove(dentry->d_inode->u.generic_ip, &er);
1144 struct inode_operations gfs2_file_iops = {
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 struct inode_operations gfs2_dev_iops = {
1155 .permission = gfs2_permission,
1156 .setattr = gfs2_setattr,
1157 .getattr = gfs2_getattr,
1158 .setxattr = gfs2_setxattr,
1159 .getxattr = gfs2_getxattr,
1160 .listxattr = gfs2_listxattr,
1161 .removexattr = gfs2_removexattr,
1164 struct inode_operations gfs2_dir_iops = {
1165 .create = gfs2_create,
1166 .lookup = gfs2_lookup,
1168 .unlink = gfs2_unlink,
1169 .symlink = gfs2_symlink,
1170 .mkdir = gfs2_mkdir,
1171 .rmdir = gfs2_rmdir,
1172 .mknod = gfs2_mknod,
1173 .rename = gfs2_rename,
1174 .permission = gfs2_permission,
1175 .setattr = gfs2_setattr,
1176 .getattr = gfs2_getattr,
1177 .setxattr = gfs2_setxattr,
1178 .getxattr = gfs2_getxattr,
1179 .listxattr = gfs2_listxattr,
1180 .removexattr = gfs2_removexattr,
1183 struct inode_operations gfs2_symlink_iops = {
1184 .readlink = gfs2_readlink,
1185 .follow_link = gfs2_follow_link,
1186 .permission = gfs2_permission,
1187 .setattr = gfs2_setattr,
1188 .getattr = gfs2_getattr,
1189 .setxattr = gfs2_setxattr,
1190 .getxattr = gfs2_getxattr,
1191 .listxattr = gfs2_listxattr,
1192 .removexattr = gfs2_removexattr,