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/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 <linux/lm_interface.h>
23 #include <asm/uaccess.h>
35 #include "ops_dentry.h"
36 #include "ops_inode.h"
43 * gfs2_create - Create a file
44 * @dir: The directory in which to create the file
45 * @dentry: The dentry of the new file
46 * @mode: The mode of the new file
51 static int gfs2_create(struct inode *dir, struct dentry *dentry,
52 int mode, struct nameidata *nd)
54 struct gfs2_inode *dip = GFS2_I(dir);
55 struct gfs2_sbd *sdp = GFS2_SB(dir);
56 struct gfs2_holder ghs[2];
59 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
62 inode = gfs2_createi(ghs, &dentry->d_name, S_IFREG | mode);
65 if (dip->i_alloc.al_rgd)
66 gfs2_inplace_release(dip);
67 gfs2_quota_unlock(dip);
69 gfs2_glock_dq_uninit_m(2, ghs);
70 mark_inode_dirty(inode);
72 } else if (PTR_ERR(inode) != -EEXIST ||
73 (nd->intent.open.flags & O_EXCL)) {
74 gfs2_holder_uninit(ghs);
75 return PTR_ERR(inode);
78 inode = gfs2_lookupi(dir, &dentry->d_name, 0, nd);
81 gfs2_holder_uninit(ghs);
84 gfs2_holder_uninit(ghs);
85 return PTR_ERR(inode);
90 d_instantiate(dentry, inode);
96 * gfs2_lookup - Look up a filename in a directory and return its inode
97 * @dir: The directory inode
98 * @dentry: The dentry of the new inode
99 * @nd: passed from Linux VFS, ignored by us
101 * Called by the VFS layer. Lock dir and call gfs2_lookupi()
106 static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry,
107 struct nameidata *nd)
109 struct inode *inode = NULL;
111 dentry->d_op = &gfs2_dops;
113 inode = gfs2_lookupi(dir, &dentry->d_name, 0, nd);
114 if (inode && IS_ERR(inode))
115 return ERR_PTR(PTR_ERR(inode));
118 return d_splice_alias(inode, dentry);
119 d_add(dentry, inode);
125 * gfs2_link - Link to a file
126 * @old_dentry: The inode to link
127 * @dir: Add link to this directory
128 * @dentry: The name of the link
130 * Link the inode in "old_dentry" into the directory "dir" with the
136 static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
137 struct dentry *dentry)
139 struct gfs2_inode *dip = GFS2_I(dir);
140 struct gfs2_sbd *sdp = GFS2_SB(dir);
141 struct inode *inode = old_dentry->d_inode;
142 struct gfs2_inode *ip = GFS2_I(inode);
143 struct gfs2_holder ghs[2];
147 if (S_ISDIR(ip->i_di.di_mode))
150 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
151 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
153 error = gfs2_glock_nq_m(2, ghs);
157 error = permission(dir, MAY_WRITE | MAY_EXEC, NULL);
161 error = gfs2_dir_search(dir, &dentry->d_name, NULL, NULL);
172 if (!dip->i_di.di_nlink)
175 if (dip->i_di.di_entries == (u32)-1)
178 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
181 if (!ip->i_di.di_nlink)
184 if (ip->i_di.di_nlink == (u32)-1)
187 alloc_required = error = gfs2_diradd_alloc_required(dir, &dentry->d_name);
192 if (alloc_required) {
193 struct gfs2_alloc *al = gfs2_alloc_get(dip);
195 error = gfs2_quota_lock(dip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
199 error = gfs2_quota_check(dip, dip->i_di.di_uid,
204 al->al_requested = sdp->sd_max_dirres;
206 error = gfs2_inplace_reserve(dip);
210 error = gfs2_trans_begin(sdp, sdp->sd_max_dirres +
211 al->al_rgd->rd_ri.ri_length +
212 2 * RES_DINODE + RES_STATFS +
217 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + RES_LEAF, 0);
222 error = gfs2_dir_add(dir, &dentry->d_name, &ip->i_num,
223 IF2DT(ip->i_di.di_mode));
227 error = gfs2_change_nlink(ip, +1);
233 gfs2_inplace_release(dip);
236 gfs2_quota_unlock(dip);
241 gfs2_glock_dq_m(2, ghs);
243 gfs2_holder_uninit(ghs);
244 gfs2_holder_uninit(ghs + 1);
246 atomic_inc(&inode->i_count);
247 d_instantiate(dentry, inode);
248 mark_inode_dirty(inode);
254 * gfs2_unlink - Unlink a file
255 * @dir: The inode of the directory containing the file to unlink
256 * @dentry: The file itself
258 * Unlink a file. Call gfs2_unlinki()
263 static int gfs2_unlink(struct inode *dir, struct dentry *dentry)
265 struct gfs2_inode *dip = GFS2_I(dir);
266 struct gfs2_sbd *sdp = GFS2_SB(dir);
267 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
268 struct gfs2_holder ghs[2];
271 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
272 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
274 error = gfs2_glock_nq_m(2, ghs);
278 error = gfs2_unlink_ok(dip, &dentry->d_name, ip);
282 error = gfs2_trans_begin(sdp, 2*RES_DINODE + RES_LEAF + RES_RG_BIT, 0);
286 error = gfs2_dir_del(dip, &dentry->d_name);
290 error = gfs2_change_nlink(ip, -1);
295 gfs2_glock_dq_m(2, ghs);
297 gfs2_holder_uninit(ghs);
298 gfs2_holder_uninit(ghs + 1);
303 * gfs2_symlink - Create a symlink
304 * @dir: The directory to create the symlink in
305 * @dentry: The dentry to put the symlink in
306 * @symname: The thing which the link points to
311 static int gfs2_symlink(struct inode *dir, struct dentry *dentry,
314 struct gfs2_inode *dip = GFS2_I(dir), *ip;
315 struct gfs2_sbd *sdp = GFS2_SB(dir);
316 struct gfs2_holder ghs[2];
318 struct buffer_head *dibh;
322 /* Must be stuffed with a null terminator for gfs2_follow_link() */
323 size = strlen(symname);
324 if (size > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode) - 1)
325 return -ENAMETOOLONG;
327 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
329 inode = gfs2_createi(ghs, &dentry->d_name, S_IFLNK | S_IRWXUGO);
331 gfs2_holder_uninit(ghs);
332 return PTR_ERR(inode);
335 ip = ghs[1].gh_gl->gl_object;
337 ip->i_di.di_size = size;
339 error = gfs2_meta_inode_buffer(ip, &dibh);
341 if (!gfs2_assert_withdraw(sdp, !error)) {
342 gfs2_dinode_out(&ip->i_di, dibh->b_data);
343 memcpy(dibh->b_data + sizeof(struct gfs2_dinode), symname,
349 if (dip->i_alloc.al_rgd)
350 gfs2_inplace_release(dip);
351 gfs2_quota_unlock(dip);
354 gfs2_glock_dq_uninit_m(2, ghs);
356 d_instantiate(dentry, inode);
357 mark_inode_dirty(inode);
363 * gfs2_mkdir - Make a directory
364 * @dir: The parent directory of the new one
365 * @dentry: The dentry of the new directory
366 * @mode: The mode of the new directory
371 static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode)
373 struct gfs2_inode *dip = GFS2_I(dir), *ip;
374 struct gfs2_sbd *sdp = GFS2_SB(dir);
375 struct gfs2_holder ghs[2];
377 struct buffer_head *dibh;
380 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
382 inode = gfs2_createi(ghs, &dentry->d_name, S_IFDIR | mode);
384 gfs2_holder_uninit(ghs);
385 return PTR_ERR(inode);
388 ip = ghs[1].gh_gl->gl_object;
390 ip->i_di.di_nlink = 2;
391 ip->i_di.di_size = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode);
392 ip->i_di.di_flags |= GFS2_DIF_JDATA;
393 ip->i_di.di_payload_format = GFS2_FORMAT_DE;
394 ip->i_di.di_entries = 2;
396 error = gfs2_meta_inode_buffer(ip, &dibh);
398 if (!gfs2_assert_withdraw(sdp, !error)) {
399 struct gfs2_dinode *di = (struct gfs2_dinode *)dibh->b_data;
400 struct gfs2_dirent *dent = (struct gfs2_dirent *)(di+1);
403 gfs2_str2qstr(&str, ".");
404 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
405 gfs2_qstr2dirent(&str, GFS2_DIRENT_SIZE(str.len), dent);
406 dent->de_inum = di->di_num; /* already GFS2 endian */
407 dent->de_type = cpu_to_be16(DT_DIR);
408 di->di_entries = cpu_to_be32(1);
410 gfs2_str2qstr(&str, "..");
411 dent = (struct gfs2_dirent *)((char*)dent + GFS2_DIRENT_SIZE(1));
412 gfs2_qstr2dirent(&str, dibh->b_size - GFS2_DIRENT_SIZE(1) - sizeof(struct gfs2_dinode), dent);
414 gfs2_inum_out(&dip->i_num, &dent->de_inum);
415 dent->de_type = cpu_to_be16(DT_DIR);
417 gfs2_dinode_out(&ip->i_di, di);
422 error = gfs2_change_nlink(dip, +1);
423 gfs2_assert_withdraw(sdp, !error); /* dip already pinned */
426 if (dip->i_alloc.al_rgd)
427 gfs2_inplace_release(dip);
428 gfs2_quota_unlock(dip);
431 gfs2_glock_dq_uninit_m(2, ghs);
433 d_instantiate(dentry, inode);
434 mark_inode_dirty(inode);
440 * gfs2_rmdir - Remove a directory
441 * @dir: The parent directory of the directory to be removed
442 * @dentry: The dentry of the directory to remove
444 * Remove a directory. Call gfs2_rmdiri()
449 static int gfs2_rmdir(struct inode *dir, struct dentry *dentry)
451 struct gfs2_inode *dip = GFS2_I(dir);
452 struct gfs2_sbd *sdp = GFS2_SB(dir);
453 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
454 struct gfs2_holder ghs[2];
457 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
458 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
460 error = gfs2_glock_nq_m(2, ghs);
464 error = gfs2_unlink_ok(dip, &dentry->d_name, ip);
468 if (ip->i_di.di_entries < 2) {
469 if (gfs2_consist_inode(ip))
470 gfs2_dinode_print(&ip->i_di);
474 if (ip->i_di.di_entries > 2) {
479 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + 3 * RES_LEAF + RES_RG_BIT, 0);
483 error = gfs2_rmdiri(dip, &dentry->d_name, ip);
488 gfs2_glock_dq_m(2, ghs);
490 gfs2_holder_uninit(ghs);
491 gfs2_holder_uninit(ghs + 1);
496 * gfs2_mknod - Make a special file
497 * @dir: The directory in which the special file will reside
498 * @dentry: The dentry of the special file
499 * @mode: The mode of the special file
500 * @rdev: The device specification of the special file
504 static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode,
507 struct gfs2_inode *dip = GFS2_I(dir), *ip;
508 struct gfs2_sbd *sdp = GFS2_SB(dir);
509 struct gfs2_holder ghs[2];
511 struct buffer_head *dibh;
512 u32 major = 0, minor = 0;
515 switch (mode & S_IFMT) {
528 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
530 inode = gfs2_createi(ghs, &dentry->d_name, mode);
532 gfs2_holder_uninit(ghs);
533 return PTR_ERR(inode);
536 ip = ghs[1].gh_gl->gl_object;
538 ip->i_di.di_major = major;
539 ip->i_di.di_minor = minor;
541 error = gfs2_meta_inode_buffer(ip, &dibh);
543 if (!gfs2_assert_withdraw(sdp, !error)) {
544 gfs2_dinode_out(&ip->i_di, dibh->b_data);
549 if (dip->i_alloc.al_rgd)
550 gfs2_inplace_release(dip);
551 gfs2_quota_unlock(dip);
554 gfs2_glock_dq_uninit_m(2, ghs);
556 d_instantiate(dentry, inode);
557 mark_inode_dirty(inode);
563 * gfs2_rename - Rename a file
564 * @odir: Parent directory of old file name
565 * @odentry: The old dentry of the file
566 * @ndir: Parent directory of new file name
567 * @ndentry: The new dentry of the file
572 static int gfs2_rename(struct inode *odir, struct dentry *odentry,
573 struct inode *ndir, struct dentry *ndentry)
575 struct gfs2_inode *odip = GFS2_I(odir);
576 struct gfs2_inode *ndip = GFS2_I(ndir);
577 struct gfs2_inode *ip = GFS2_I(odentry->d_inode);
578 struct gfs2_inode *nip = NULL;
579 struct gfs2_sbd *sdp = GFS2_SB(odir);
580 struct gfs2_holder ghs[4], r_gh;
587 if (ndentry->d_inode) {
588 nip = GFS2_I(ndentry->d_inode);
593 /* Make sure we aren't trying to move a dirctory into it's subdir */
595 if (S_ISDIR(ip->i_di.di_mode) && odip != ndip) {
598 error = gfs2_glock_nq_init(sdp->sd_rename_gl,
604 error = gfs2_ok_to_move(ip, ndip);
610 gfs2_holder_init(odip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
612 gfs2_holder_init(ndip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
615 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
619 gfs2_holder_init(nip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
623 error = gfs2_glock_nq_m(num_gh, ghs);
627 /* Check out the old directory */
629 error = gfs2_unlink_ok(odip, &odentry->d_name, ip);
633 /* Check out the new directory */
636 error = gfs2_unlink_ok(ndip, &ndentry->d_name, nip);
640 if (S_ISDIR(nip->i_di.di_mode)) {
641 if (nip->i_di.di_entries < 2) {
642 if (gfs2_consist_inode(nip))
643 gfs2_dinode_print(&nip->i_di);
647 if (nip->i_di.di_entries > 2) {
653 error = permission(ndir, MAY_WRITE | MAY_EXEC, NULL);
657 error = gfs2_dir_search(ndir, &ndentry->d_name, NULL, NULL);
669 if (!ndip->i_di.di_nlink) {
673 if (ndip->i_di.di_entries == (u32)-1) {
677 if (S_ISDIR(ip->i_di.di_mode) &&
678 ndip->i_di.di_nlink == (u32)-1) {
685 /* Check out the dir to be renamed */
688 error = permission(odentry->d_inode, MAY_WRITE, NULL);
693 alloc_required = error = gfs2_diradd_alloc_required(ndir, &ndentry->d_name);
698 if (alloc_required) {
699 struct gfs2_alloc *al = gfs2_alloc_get(ndip);
701 error = gfs2_quota_lock(ndip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
705 error = gfs2_quota_check(ndip, ndip->i_di.di_uid,
710 al->al_requested = sdp->sd_max_dirres;
712 error = gfs2_inplace_reserve(ndip);
716 error = gfs2_trans_begin(sdp, sdp->sd_max_dirres +
717 al->al_rgd->rd_ri.ri_length +
718 4 * RES_DINODE + 4 * RES_LEAF +
719 RES_STATFS + RES_QUOTA, 0);
723 error = gfs2_trans_begin(sdp, 4 * RES_DINODE +
729 /* Remove the target file, if it exists */
732 if (S_ISDIR(nip->i_di.di_mode))
733 error = gfs2_rmdiri(ndip, &ndentry->d_name, nip);
735 error = gfs2_dir_del(ndip, &ndentry->d_name);
738 error = gfs2_change_nlink(nip, -1);
746 gfs2_str2qstr(&name, "..");
748 error = gfs2_change_nlink(ndip, +1);
751 error = gfs2_change_nlink(odip, -1);
755 error = gfs2_dir_mvino(ip, &name, &ndip->i_num, DT_DIR);
759 struct buffer_head *dibh;
760 error = gfs2_meta_inode_buffer(ip, &dibh);
763 ip->i_di.di_ctime = get_seconds();
764 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
765 gfs2_dinode_out(&ip->i_di, dibh->b_data);
769 error = gfs2_dir_del(odip, &odentry->d_name);
773 error = gfs2_dir_add(ndir, &ndentry->d_name, &ip->i_num,
774 IF2DT(ip->i_di.di_mode));
782 gfs2_inplace_release(ndip);
785 gfs2_quota_unlock(ndip);
788 gfs2_alloc_put(ndip);
790 gfs2_glock_dq_m(num_gh, ghs);
792 for (x = 0; x < num_gh; x++)
793 gfs2_holder_uninit(ghs + x);
796 gfs2_glock_dq_uninit(&r_gh);
802 * gfs2_readlink - Read the value of a symlink
803 * @dentry: the symlink
804 * @buf: the buffer to read the symlink data into
805 * @size: the size of the buffer
810 static int gfs2_readlink(struct dentry *dentry, char __user *user_buf,
813 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
814 char array[GFS2_FAST_NAME_SIZE], *buf = array;
815 unsigned int len = GFS2_FAST_NAME_SIZE;
818 error = gfs2_readlinki(ip, &buf, &len);
822 if (user_size > len - 1)
825 if (copy_to_user(user_buf, buf, user_size))
837 * gfs2_follow_link - Follow a symbolic link
838 * @dentry: The dentry of the link
839 * @nd: Data that we pass to vfs_follow_link()
841 * This can handle symlinks of any size. It is optimised for symlinks
842 * under GFS2_FAST_NAME_SIZE.
844 * Returns: 0 on success or error code
847 static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd)
849 struct gfs2_inode *ip = GFS2_I(dentry->d_inode);
850 char array[GFS2_FAST_NAME_SIZE], *buf = array;
851 unsigned int len = GFS2_FAST_NAME_SIZE;
854 error = gfs2_readlinki(ip, &buf, &len);
856 error = vfs_follow_link(nd, buf);
861 return ERR_PTR(error);
868 * @nd: passed from Linux VFS, ignored by us
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;
879 if (ip->i_vn == ip->i_gl->gl_vn)
880 return generic_permission(inode, mask, gfs2_check_acl);
882 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh);
884 error = generic_permission(inode, mask, gfs2_check_acl_locked);
885 gfs2_glock_dq_uninit(&i_gh);
891 static int setattr_size(struct inode *inode, struct iattr *attr)
893 struct gfs2_inode *ip = GFS2_I(inode);
896 if (attr->ia_size != ip->i_di.di_size) {
897 error = vmtruncate(inode, attr->ia_size);
902 error = gfs2_truncatei(ip, attr->ia_size);
909 static int setattr_chown(struct inode *inode, struct iattr *attr)
911 struct gfs2_inode *ip = GFS2_I(inode);
912 struct gfs2_sbd *sdp = GFS2_SB(inode);
913 struct buffer_head *dibh;
914 u32 ouid, ogid, nuid, ngid;
917 ouid = ip->i_di.di_uid;
918 ogid = ip->i_di.di_gid;
922 if (!(attr->ia_valid & ATTR_UID) || ouid == nuid)
923 ouid = nuid = NO_QUOTA_CHANGE;
924 if (!(attr->ia_valid & ATTR_GID) || ogid == ngid)
925 ogid = ngid = NO_QUOTA_CHANGE;
929 error = gfs2_quota_lock(ip, nuid, ngid);
933 if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) {
934 error = gfs2_quota_check(ip, nuid, ngid);
939 error = gfs2_trans_begin(sdp, RES_DINODE + 2 * RES_QUOTA, 0);
943 error = gfs2_meta_inode_buffer(ip, &dibh);
947 error = inode_setattr(inode, attr);
948 gfs2_assert_warn(sdp, !error);
949 gfs2_inode_attr_out(ip);
951 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
952 gfs2_dinode_out(&ip->i_di, dibh->b_data);
955 if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) {
956 gfs2_quota_change(ip, -ip->i_di.di_blocks, ouid, ogid);
957 gfs2_quota_change(ip, ip->i_di.di_blocks, nuid, ngid);
963 gfs2_quota_unlock(ip);
970 * gfs2_setattr - Change attributes on an inode
971 * @dentry: The dentry which is changing
972 * @attr: The structure describing the change
974 * The VFS layer wants to change one or more of an inodes attributes. Write
975 * that change out to disk.
980 static int gfs2_setattr(struct dentry *dentry, struct iattr *attr)
982 struct inode *inode = dentry->d_inode;
983 struct gfs2_inode *ip = GFS2_I(inode);
984 struct gfs2_holder i_gh;
987 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh);
992 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
995 error = inode_change_ok(inode, attr);
999 if (attr->ia_valid & ATTR_SIZE)
1000 error = setattr_size(inode, attr);
1001 else if (attr->ia_valid & (ATTR_UID | ATTR_GID))
1002 error = setattr_chown(inode, attr);
1003 else if ((attr->ia_valid & ATTR_MODE) && IS_POSIXACL(inode))
1004 error = gfs2_acl_chmod(ip, attr);
1006 error = gfs2_setattr_simple(ip, attr);
1009 gfs2_glock_dq_uninit(&i_gh);
1011 mark_inode_dirty(inode);
1016 * gfs2_getattr - Read out an inode's attributes
1017 * @mnt: The vfsmount the inode is being accessed from
1018 * @dentry: The dentry to stat
1019 * @stat: The inode's stats
1024 static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry,
1027 struct inode *inode = dentry->d_inode;
1028 struct gfs2_inode *ip = GFS2_I(inode);
1029 struct gfs2_holder gh;
1032 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
1034 generic_fillattr(inode, stat);
1035 gfs2_glock_dq_uninit(&gh);
1041 static int gfs2_setxattr(struct dentry *dentry, const char *name,
1042 const void *data, size_t size, int flags)
1044 struct inode *inode = dentry->d_inode;
1045 struct gfs2_ea_request er;
1047 memset(&er, 0, sizeof(struct gfs2_ea_request));
1048 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1049 if (er.er_type == GFS2_EATYPE_UNUSED)
1051 er.er_data = (char *)data;
1052 er.er_name_len = strlen(er.er_name);
1053 er.er_data_len = size;
1054 er.er_flags = flags;
1056 gfs2_assert_warn(GFS2_SB(inode), !(er.er_flags & GFS2_ERF_MODE));
1058 return gfs2_ea_set(GFS2_I(inode), &er);
1061 static ssize_t gfs2_getxattr(struct dentry *dentry, const char *name,
1062 void *data, size_t size)
1064 struct gfs2_ea_request er;
1066 memset(&er, 0, sizeof(struct gfs2_ea_request));
1067 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1068 if (er.er_type == GFS2_EATYPE_UNUSED)
1071 er.er_name_len = strlen(er.er_name);
1072 er.er_data_len = size;
1074 return gfs2_ea_get(GFS2_I(dentry->d_inode), &er);
1077 static ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size)
1079 struct gfs2_ea_request er;
1081 memset(&er, 0, sizeof(struct gfs2_ea_request));
1082 er.er_data = (size) ? buffer : NULL;
1083 er.er_data_len = size;
1085 return gfs2_ea_list(GFS2_I(dentry->d_inode), &er);
1088 static int gfs2_removexattr(struct dentry *dentry, const char *name)
1090 struct gfs2_ea_request er;
1092 memset(&er, 0, sizeof(struct gfs2_ea_request));
1093 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1094 if (er.er_type == GFS2_EATYPE_UNUSED)
1096 er.er_name_len = strlen(er.er_name);
1098 return gfs2_ea_remove(GFS2_I(dentry->d_inode), &er);
1101 struct inode_operations gfs2_file_iops = {
1102 .permission = gfs2_permission,
1103 .setattr = gfs2_setattr,
1104 .getattr = gfs2_getattr,
1105 .setxattr = gfs2_setxattr,
1106 .getxattr = gfs2_getxattr,
1107 .listxattr = gfs2_listxattr,
1108 .removexattr = gfs2_removexattr,
1111 struct inode_operations gfs2_dev_iops = {
1112 .permission = gfs2_permission,
1113 .setattr = gfs2_setattr,
1114 .getattr = gfs2_getattr,
1115 .setxattr = gfs2_setxattr,
1116 .getxattr = gfs2_getxattr,
1117 .listxattr = gfs2_listxattr,
1118 .removexattr = gfs2_removexattr,
1121 struct inode_operations gfs2_dir_iops = {
1122 .create = gfs2_create,
1123 .lookup = gfs2_lookup,
1125 .unlink = gfs2_unlink,
1126 .symlink = gfs2_symlink,
1127 .mkdir = gfs2_mkdir,
1128 .rmdir = gfs2_rmdir,
1129 .mknod = gfs2_mknod,
1130 .rename = gfs2_rename,
1131 .permission = gfs2_permission,
1132 .setattr = gfs2_setattr,
1133 .getattr = gfs2_getattr,
1134 .setxattr = gfs2_setxattr,
1135 .getxattr = gfs2_getxattr,
1136 .listxattr = gfs2_listxattr,
1137 .removexattr = gfs2_removexattr,
1140 struct inode_operations gfs2_symlink_iops = {
1141 .readlink = gfs2_readlink,
1142 .follow_link = gfs2_follow_link,
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,