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 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"
44 * gfs2_create - Create a file
45 * @dir: The directory in which to create the file
46 * @dentry: The dentry of the new file
47 * @mode: The mode of the new file
52 static int gfs2_create(struct inode *dir, struct dentry *dentry,
53 int mode, struct nameidata *nd)
55 struct gfs2_inode *dip = GFS2_I(dir);
56 struct gfs2_sbd *sdp = GFS2_SB(dir);
57 struct gfs2_holder ghs[2];
60 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
63 inode = gfs2_createi(ghs, &dentry->d_name, S_IFREG | mode);
66 if (dip->i_alloc.al_rgd)
67 gfs2_inplace_release(dip);
68 gfs2_quota_unlock(dip);
70 gfs2_glock_dq_uninit_m(2, ghs);
71 mark_inode_dirty(inode);
73 } else if (PTR_ERR(inode) != -EEXIST ||
74 (nd->intent.open.flags & O_EXCL)) {
75 gfs2_holder_uninit(ghs);
76 return PTR_ERR(inode);
79 inode = gfs2_lookupi(dir, &dentry->d_name, 0, nd);
82 gfs2_holder_uninit(ghs);
85 gfs2_holder_uninit(ghs);
86 return PTR_ERR(inode);
91 d_instantiate(dentry, inode);
97 * gfs2_lookup - Look up a filename in a directory and return its inode
98 * @dir: The directory inode
99 * @dentry: The dentry of the new inode
100 * @nd: passed from Linux VFS, ignored by us
102 * Called by the VFS layer. Lock dir and call gfs2_lookupi()
107 static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry,
108 struct nameidata *nd)
110 struct inode *inode = NULL;
112 dentry->d_op = &gfs2_dops;
114 inode = gfs2_lookupi(dir, &dentry->d_name, 0, nd);
115 if (inode && IS_ERR(inode))
116 return ERR_PTR(PTR_ERR(inode));
119 return d_splice_alias(inode, dentry);
120 d_add(dentry, inode);
126 * gfs2_link - Link to a file
127 * @old_dentry: The inode to link
128 * @dir: Add link to this directory
129 * @dentry: The name of the link
131 * Link the inode in "old_dentry" into the directory "dir" with the
137 static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
138 struct dentry *dentry)
140 struct gfs2_inode *dip = GFS2_I(dir);
141 struct gfs2_sbd *sdp = GFS2_SB(dir);
142 struct inode *inode = old_dentry->d_inode;
143 struct gfs2_inode *ip = GFS2_I(inode);
144 struct gfs2_holder ghs[2];
148 if (S_ISDIR(ip->i_di.di_mode))
151 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
152 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
154 error = gfs2_glock_nq_m(2, ghs);
158 error = gfs2_repermission(dir, MAY_WRITE | MAY_EXEC, NULL);
162 error = gfs2_dir_search(dir, &dentry->d_name, NULL, NULL);
173 if (!dip->i_di.di_nlink)
176 if (dip->i_di.di_entries == (uint32_t)-1)
179 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
182 if (!ip->i_di.di_nlink)
185 if (ip->i_di.di_nlink == (uint32_t)-1)
188 alloc_required = error = gfs2_diradd_alloc_required(dir, &dentry->d_name);
193 if (alloc_required) {
194 struct gfs2_alloc *al = gfs2_alloc_get(dip);
196 error = gfs2_quota_lock(dip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
200 error = gfs2_quota_check(dip, dip->i_di.di_uid,
205 al->al_requested = sdp->sd_max_dirres;
207 error = gfs2_inplace_reserve(dip);
211 error = gfs2_trans_begin(sdp, sdp->sd_max_dirres +
212 al->al_rgd->rd_ri.ri_length +
213 2 * RES_DINODE + RES_STATFS +
218 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + RES_LEAF, 0);
223 error = gfs2_dir_add(dir, &dentry->d_name, &ip->i_num,
224 IF2DT(ip->i_di.di_mode));
228 error = gfs2_change_nlink(ip, +1);
235 gfs2_inplace_release(dip);
239 gfs2_quota_unlock(dip);
246 gfs2_glock_dq_m(2, ghs);
249 gfs2_holder_uninit(ghs);
250 gfs2_holder_uninit(ghs + 1);
253 d_instantiate(dentry, inode);
254 mark_inode_dirty(inode);
261 * gfs2_unlink - Unlink a file
262 * @dir: The inode of the directory containing the file to unlink
263 * @dentry: The file itself
265 * Unlink a file. Call gfs2_unlinki()
270 static int gfs2_unlink(struct inode *dir, struct dentry *dentry)
272 struct gfs2_inode *dip = GFS2_I(dir);
273 struct gfs2_sbd *sdp = GFS2_SB(dir);
274 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
275 struct gfs2_holder ghs[2];
278 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
279 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
281 error = gfs2_glock_nq_m(2, 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(2, ghs);
304 gfs2_holder_uninit(ghs);
305 gfs2_holder_uninit(ghs + 1);
310 * gfs2_symlink - Create a symlink
311 * @dir: The directory to create the symlink in
312 * @dentry: The dentry to put the symlink in
313 * @symname: The thing which the link points to
318 static int gfs2_symlink(struct inode *dir, struct dentry *dentry,
321 struct gfs2_inode *dip = GFS2_I(dir), *ip;
322 struct gfs2_sbd *sdp = GFS2_SB(dir);
323 struct gfs2_holder ghs[2];
325 struct buffer_head *dibh;
329 /* Must be stuffed with a null terminator for gfs2_follow_link() */
330 size = strlen(symname);
331 if (size > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode) - 1)
332 return -ENAMETOOLONG;
334 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
336 inode = gfs2_createi(ghs, &dentry->d_name, S_IFLNK | S_IRWXUGO);
338 gfs2_holder_uninit(ghs);
339 return PTR_ERR(inode);
342 ip = ghs[1].gh_gl->gl_object;
344 ip->i_di.di_size = size;
346 error = gfs2_meta_inode_buffer(ip, &dibh);
348 if (!gfs2_assert_withdraw(sdp, !error)) {
349 gfs2_dinode_out(&ip->i_di, dibh->b_data);
350 memcpy(dibh->b_data + sizeof(struct gfs2_dinode), symname,
356 if (dip->i_alloc.al_rgd)
357 gfs2_inplace_release(dip);
358 gfs2_quota_unlock(dip);
361 gfs2_glock_dq_uninit_m(2, ghs);
363 d_instantiate(dentry, inode);
364 mark_inode_dirty(inode);
370 * gfs2_mkdir - Make a directory
371 * @dir: The parent directory of the new one
372 * @dentry: The dentry of the new directory
373 * @mode: The mode of the new directory
378 static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode)
380 struct gfs2_inode *dip = GFS2_I(dir), *ip;
381 struct gfs2_sbd *sdp = GFS2_SB(dir);
382 struct gfs2_holder ghs[2];
384 struct buffer_head *dibh;
387 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
389 inode = gfs2_createi(ghs, &dentry->d_name, S_IFDIR | mode);
391 gfs2_holder_uninit(ghs);
392 return PTR_ERR(inode);
395 ip = ghs[1].gh_gl->gl_object;
397 ip->i_di.di_nlink = 2;
398 ip->i_di.di_size = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode);
399 ip->i_di.di_flags |= GFS2_DIF_JDATA;
400 ip->i_di.di_payload_format = GFS2_FORMAT_DE;
401 ip->i_di.di_entries = 2;
403 error = gfs2_meta_inode_buffer(ip, &dibh);
405 if (!gfs2_assert_withdraw(sdp, !error)) {
406 struct gfs2_dinode *di = (struct gfs2_dinode *)dibh->b_data;
407 struct gfs2_dirent *dent = (struct gfs2_dirent *)(di+1);
410 gfs2_str2qstr(&str, ".");
411 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
412 gfs2_qstr2dirent(&str, GFS2_DIRENT_SIZE(str.len), dent);
413 dent->de_inum = di->di_num; /* already GFS2 endian */
414 dent->de_type = DT_DIR;
415 di->di_entries = cpu_to_be32(1);
417 gfs2_str2qstr(&str, "..");
418 dent = (struct gfs2_dirent *)((char*)dent + GFS2_DIRENT_SIZE(1));
419 gfs2_qstr2dirent(&str, dibh->b_size - GFS2_DIRENT_SIZE(1) - sizeof(struct gfs2_dinode), dent);
421 gfs2_inum_out(&dip->i_num, (char *) &dent->de_inum);
422 dent->de_type = DT_DIR;
424 gfs2_dinode_out(&ip->i_di, (char *)di);
429 error = gfs2_change_nlink(dip, +1);
430 gfs2_assert_withdraw(sdp, !error); /* dip already pinned */
433 if (dip->i_alloc.al_rgd)
434 gfs2_inplace_release(dip);
435 gfs2_quota_unlock(dip);
438 gfs2_glock_dq_uninit_m(2, ghs);
440 d_instantiate(dentry, inode);
441 mark_inode_dirty(inode);
447 * gfs2_rmdir - Remove a directory
448 * @dir: The parent directory of the directory to be removed
449 * @dentry: The dentry of the directory to remove
451 * Remove a directory. Call gfs2_rmdiri()
456 static int gfs2_rmdir(struct inode *dir, struct dentry *dentry)
458 struct gfs2_inode *dip = GFS2_I(dir);
459 struct gfs2_sbd *sdp = GFS2_SB(dir);
460 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
461 struct gfs2_holder ghs[2];
464 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
465 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
467 error = gfs2_glock_nq_m(2, ghs);
471 error = gfs2_unlink_ok(dip, &dentry->d_name, ip);
475 if (ip->i_di.di_entries < 2) {
476 if (gfs2_consist_inode(ip))
477 gfs2_dinode_print(&ip->i_di);
481 if (ip->i_di.di_entries > 2) {
486 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + 3 * RES_LEAF + RES_RG_BIT, 0);
490 error = gfs2_rmdiri(dip, &dentry->d_name, ip);
495 gfs2_glock_dq_m(2, ghs);
498 gfs2_holder_uninit(ghs);
499 gfs2_holder_uninit(ghs + 1);
505 * gfs2_mknod - Make a special file
506 * @dir: The directory in which the special file will reside
507 * @dentry: The dentry of the special file
508 * @mode: The mode of the special file
509 * @rdev: The device specification of the special file
513 static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode,
516 struct gfs2_inode *dip = GFS2_I(dir), *ip;
517 struct gfs2_sbd *sdp = GFS2_SB(dir);
518 struct gfs2_holder ghs[2];
520 struct buffer_head *dibh;
521 uint32_t major = 0, minor = 0;
524 switch (mode & S_IFMT) {
537 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
539 inode = gfs2_createi(ghs, &dentry->d_name, mode);
541 gfs2_holder_uninit(ghs);
542 return PTR_ERR(inode);
545 ip = ghs[1].gh_gl->gl_object;
547 ip->i_di.di_major = major;
548 ip->i_di.di_minor = minor;
550 error = gfs2_meta_inode_buffer(ip, &dibh);
552 if (!gfs2_assert_withdraw(sdp, !error)) {
553 gfs2_dinode_out(&ip->i_di, dibh->b_data);
558 if (dip->i_alloc.al_rgd)
559 gfs2_inplace_release(dip);
560 gfs2_quota_unlock(dip);
563 gfs2_glock_dq_uninit_m(2, ghs);
565 d_instantiate(dentry, inode);
566 mark_inode_dirty(inode);
572 * gfs2_rename - Rename a file
573 * @odir: Parent directory of old file name
574 * @odentry: The old dentry of the file
575 * @ndir: Parent directory of new file name
576 * @ndentry: The new dentry of the file
581 static int gfs2_rename(struct inode *odir, struct dentry *odentry,
582 struct inode *ndir, struct dentry *ndentry)
584 struct gfs2_inode *odip = GFS2_I(odir);
585 struct gfs2_inode *ndip = GFS2_I(ndir);
586 struct gfs2_inode *ip = GFS2_I(odentry->d_inode);
587 struct gfs2_inode *nip = NULL;
588 struct gfs2_sbd *sdp = GFS2_SB(odir);
589 struct gfs2_holder ghs[4], r_gh;
596 if (ndentry->d_inode) {
597 nip = GFS2_I(ndentry->d_inode);
602 /* Make sure we aren't trying to move a dirctory into it's subdir */
604 if (S_ISDIR(ip->i_di.di_mode) && odip != ndip) {
607 error = gfs2_glock_nq_init(sdp->sd_rename_gl,
613 error = gfs2_ok_to_move(ip, ndip);
618 gfs2_holder_init(odip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
619 gfs2_holder_init(ndip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
620 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 2);
624 gfs2_holder_init(nip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh++);
626 error = gfs2_glock_nq_m(num_gh, ghs);
630 /* Check out the old directory */
632 error = gfs2_unlink_ok(odip, &odentry->d_name, ip);
636 /* Check out the new directory */
639 error = gfs2_unlink_ok(ndip, &ndentry->d_name, nip);
643 if (S_ISDIR(nip->i_di.di_mode)) {
644 if (nip->i_di.di_entries < 2) {
645 if (gfs2_consist_inode(nip))
646 gfs2_dinode_print(&nip->i_di);
650 if (nip->i_di.di_entries > 2) {
656 error = gfs2_repermission(ndir, MAY_WRITE | MAY_EXEC, NULL);
660 error = gfs2_dir_search(ndir, &ndentry->d_name, NULL, NULL);
672 if (!ndip->i_di.di_nlink) {
676 if (ndip->i_di.di_entries == (uint32_t)-1) {
680 if (S_ISDIR(ip->i_di.di_mode) &&
681 ndip->i_di.di_nlink == (uint32_t)-1) {
688 /* Check out the dir to be renamed */
691 error = gfs2_repermission(odentry->d_inode, MAY_WRITE, NULL);
696 alloc_required = error = gfs2_diradd_alloc_required(ndir, &ndentry->d_name);
701 if (alloc_required) {
702 struct gfs2_alloc *al = gfs2_alloc_get(ndip);
704 error = gfs2_quota_lock(ndip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
708 error = gfs2_quota_check(ndip, ndip->i_di.di_uid,
713 al->al_requested = sdp->sd_max_dirres;
715 error = gfs2_inplace_reserve(ndip);
719 error = gfs2_trans_begin(sdp, sdp->sd_max_dirres +
720 al->al_rgd->rd_ri.ri_length +
721 4 * RES_DINODE + 4 * RES_LEAF +
722 RES_STATFS + RES_QUOTA, 0);
726 error = gfs2_trans_begin(sdp, 4 * RES_DINODE +
732 /* Remove the target file, if it exists */
735 if (S_ISDIR(nip->i_di.di_mode))
736 error = gfs2_rmdiri(ndip, &ndentry->d_name, nip);
738 error = gfs2_dir_del(ndip, &ndentry->d_name);
741 error = gfs2_change_nlink(nip, -1);
749 gfs2_str2qstr(&name, "..");
751 error = gfs2_change_nlink(ndip, +1);
754 error = gfs2_change_nlink(odip, -1);
758 error = gfs2_dir_mvino(ip, &name, &ndip->i_num, DT_DIR);
762 struct buffer_head *dibh;
763 error = gfs2_meta_inode_buffer(ip, &dibh);
766 ip->i_di.di_ctime = get_seconds();
767 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
768 gfs2_dinode_out(&ip->i_di, dibh->b_data);
772 error = gfs2_dir_del(odip, &odentry->d_name);
776 error = gfs2_dir_add(ndir, &ndentry->d_name, &ip->i_num,
777 IF2DT(ip->i_di.di_mode));
785 gfs2_inplace_release(ndip);
788 gfs2_quota_unlock(ndip);
791 gfs2_alloc_put(ndip);
793 gfs2_glock_dq_m(num_gh, ghs);
795 for (x = 0; x < num_gh; x++)
796 gfs2_holder_uninit(ghs + x);
799 gfs2_glock_dq_uninit(&r_gh);
805 * gfs2_readlink - Read the value of a symlink
806 * @dentry: the symlink
807 * @buf: the buffer to read the symlink data into
808 * @size: the size of the buffer
813 static int gfs2_readlink(struct dentry *dentry, char __user *user_buf,
816 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
817 char array[GFS2_FAST_NAME_SIZE], *buf = array;
818 unsigned int len = GFS2_FAST_NAME_SIZE;
821 error = gfs2_readlinki(ip, &buf, &len);
825 if (user_size > len - 1)
828 if (copy_to_user(user_buf, buf, user_size))
840 * gfs2_follow_link - Follow a symbolic link
841 * @dentry: The dentry of the link
842 * @nd: Data that we pass to vfs_follow_link()
844 * This can handle symlinks of any size. It is optimised for symlinks
845 * under GFS2_FAST_NAME_SIZE.
847 * Returns: 0 on success or error code
850 static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd)
852 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
853 char array[GFS2_FAST_NAME_SIZE], *buf = array;
854 unsigned int len = GFS2_FAST_NAME_SIZE;
857 error = gfs2_readlinki(ip, &buf, &len);
859 error = vfs_follow_link(nd, buf);
864 return ERR_PTR(error);
871 * @nd: passed from Linux VFS, ignored by us
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;
882 if (ip->i_vn == ip->i_gl->gl_vn)
883 return generic_permission(inode, mask, gfs2_check_acl);
885 error = gfs2_glock_nq_init(ip->i_gl,
886 LM_ST_SHARED, LM_FLAG_ANY,
889 error = generic_permission(inode, mask, gfs2_check_acl_locked);
890 gfs2_glock_dq_uninit(&i_gh);
896 static int setattr_size(struct inode *inode, struct iattr *attr)
898 struct gfs2_inode *ip = GFS2_I(inode);
901 if (attr->ia_size != ip->i_di.di_size) {
902 error = vmtruncate(inode, attr->ia_size);
907 error = gfs2_truncatei(ip, attr->ia_size);
914 static int setattr_chown(struct inode *inode, struct iattr *attr)
916 struct gfs2_inode *ip = GFS2_I(inode);
917 struct gfs2_sbd *sdp = GFS2_SB(inode);
918 struct buffer_head *dibh;
919 uint32_t ouid, ogid, nuid, ngid;
922 ouid = ip->i_di.di_uid;
923 ogid = ip->i_di.di_gid;
927 if (!(attr->ia_valid & ATTR_UID) || ouid == nuid)
928 ouid = nuid = NO_QUOTA_CHANGE;
929 if (!(attr->ia_valid & ATTR_GID) || ogid == ngid)
930 ogid = ngid = NO_QUOTA_CHANGE;
934 error = gfs2_quota_lock(ip, nuid, ngid);
938 if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) {
939 error = gfs2_quota_check(ip, nuid, ngid);
944 error = gfs2_trans_begin(sdp, RES_DINODE + 2 * RES_QUOTA, 0);
948 error = gfs2_meta_inode_buffer(ip, &dibh);
952 error = inode_setattr(inode, attr);
953 gfs2_assert_warn(sdp, !error);
954 gfs2_inode_attr_out(ip);
956 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
957 gfs2_dinode_out(&ip->i_di, dibh->b_data);
960 if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) {
961 gfs2_quota_change(ip, -ip->i_di.di_blocks,
963 gfs2_quota_change(ip, ip->i_di.di_blocks,
971 gfs2_quota_unlock(ip);
980 * gfs2_setattr - Change attributes on an inode
981 * @dentry: The dentry which is changing
982 * @attr: The structure describing the change
984 * The VFS layer wants to change one or more of an inodes attributes. Write
985 * that change out to disk.
990 static int gfs2_setattr(struct dentry *dentry, struct iattr *attr)
992 struct inode *inode = dentry->d_inode;
993 struct gfs2_inode *ip = GFS2_I(inode);
994 struct gfs2_holder i_gh;
997 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh);
1002 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1005 error = inode_change_ok(inode, attr);
1009 if (attr->ia_valid & ATTR_SIZE)
1010 error = setattr_size(inode, attr);
1011 else if (attr->ia_valid & (ATTR_UID | ATTR_GID))
1012 error = setattr_chown(inode, attr);
1013 else if ((attr->ia_valid & ATTR_MODE) && IS_POSIXACL(inode))
1014 error = gfs2_acl_chmod(ip, attr);
1016 error = gfs2_setattr_simple(ip, attr);
1019 gfs2_glock_dq_uninit(&i_gh);
1022 mark_inode_dirty(inode);
1028 * gfs2_getattr - Read out an inode's attributes
1030 * @dentry: The dentry to stat
1031 * @stat: The inode's stats
1036 static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry,
1039 struct inode *inode = dentry->d_inode;
1040 struct gfs2_inode *ip = GFS2_I(inode);
1041 struct gfs2_holder gh;
1044 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
1046 generic_fillattr(inode, stat);
1047 gfs2_glock_dq_uninit(&gh);
1053 static int gfs2_setxattr(struct dentry *dentry, const char *name,
1054 const void *data, size_t size, int flags)
1056 struct inode *inode = dentry->d_inode;
1057 struct gfs2_ea_request er;
1059 memset(&er, 0, sizeof(struct gfs2_ea_request));
1060 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1061 if (er.er_type == GFS2_EATYPE_UNUSED)
1063 er.er_data = (char *)data;
1064 er.er_name_len = strlen(er.er_name);
1065 er.er_data_len = size;
1066 er.er_flags = flags;
1068 gfs2_assert_warn(GFS2_SB(inode), !(er.er_flags & GFS2_ERF_MODE));
1070 return gfs2_ea_set(GFS2_I(inode), &er);
1073 static ssize_t gfs2_getxattr(struct dentry *dentry, const char *name,
1074 void *data, size_t size)
1076 struct gfs2_ea_request er;
1078 memset(&er, 0, sizeof(struct gfs2_ea_request));
1079 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1080 if (er.er_type == GFS2_EATYPE_UNUSED)
1083 er.er_name_len = strlen(er.er_name);
1084 er.er_data_len = size;
1086 return gfs2_ea_get(GFS2_I(dentry->d_inode), &er);
1089 static ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size)
1091 struct gfs2_ea_request er;
1093 memset(&er, 0, sizeof(struct gfs2_ea_request));
1094 er.er_data = (size) ? buffer : NULL;
1095 er.er_data_len = size;
1097 return gfs2_ea_list(GFS2_I(dentry->d_inode), &er);
1100 static int gfs2_removexattr(struct dentry *dentry, const char *name)
1102 struct gfs2_ea_request er;
1104 memset(&er, 0, sizeof(struct gfs2_ea_request));
1105 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1106 if (er.er_type == GFS2_EATYPE_UNUSED)
1108 er.er_name_len = strlen(er.er_name);
1110 return gfs2_ea_remove(GFS2_I(dentry->d_inode), &er);
1113 struct inode_operations gfs2_file_iops = {
1114 .permission = gfs2_permission,
1115 .setattr = gfs2_setattr,
1116 .getattr = gfs2_getattr,
1117 .setxattr = gfs2_setxattr,
1118 .getxattr = gfs2_getxattr,
1119 .listxattr = gfs2_listxattr,
1120 .removexattr = gfs2_removexattr,
1123 struct inode_operations gfs2_dev_iops = {
1124 .permission = gfs2_permission,
1125 .setattr = gfs2_setattr,
1126 .getattr = gfs2_getattr,
1127 .setxattr = gfs2_setxattr,
1128 .getxattr = gfs2_getxattr,
1129 .listxattr = gfs2_listxattr,
1130 .removexattr = gfs2_removexattr,
1133 struct inode_operations gfs2_dir_iops = {
1134 .create = gfs2_create,
1135 .lookup = gfs2_lookup,
1137 .unlink = gfs2_unlink,
1138 .symlink = gfs2_symlink,
1139 .mkdir = gfs2_mkdir,
1140 .rmdir = gfs2_rmdir,
1141 .mknod = gfs2_mknod,
1142 .rename = gfs2_rename,
1143 .permission = gfs2_permission,
1144 .setattr = gfs2_setattr,
1145 .getattr = gfs2_getattr,
1146 .setxattr = gfs2_setxattr,
1147 .getxattr = gfs2_getxattr,
1148 .listxattr = gfs2_listxattr,
1149 .removexattr = gfs2_removexattr,
1152 struct inode_operations gfs2_symlink_iops = {
1153 .readlink = gfs2_readlink,
1154 .follow_link = gfs2_follow_link,
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,