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/semaphore.h>
23 #include <asm/uaccess.h>
26 #include "lm_interface.h"
36 #include "ops_dentry.h"
37 #include "ops_inode.h"
46 * gfs2_create - Create a file
47 * @dir: The directory in which to create the file
48 * @dentry: The dentry of the new file
49 * @mode: The mode of the new file
54 static int gfs2_create(struct inode *dir, struct dentry *dentry,
55 int mode, struct nameidata *nd)
57 struct gfs2_inode *dip = dir->u.generic_ip;
58 struct gfs2_sbd *sdp = dip->i_sbd;
59 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 inode = gfs2_lookupi(dir, &dentry->d_name, 0, nd);
85 gfs2_holder_uninit(ghs);
88 gfs2_holder_uninit(ghs);
89 return PTR_ERR(inode);
94 d_instantiate(dentry, inode);
96 mark_inode_dirty(inode);
102 * gfs2_lookup - Look up a filename in a directory and return its inode
103 * @dir: The directory inode
104 * @dentry: The dentry of the new inode
105 * @nd: passed from Linux VFS, ignored by us
107 * Called by the VFS layer. Lock dir and call gfs2_lookupi()
112 static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry,
113 struct nameidata *nd)
115 struct inode *inode = NULL;
117 dentry->d_op = &gfs2_dops;
119 inode = gfs2_lookupi(dir, &dentry->d_name, 0, nd);
120 if (inode && IS_ERR(inode))
121 return ERR_PTR(PTR_ERR(inode));
124 return d_splice_alias(inode, dentry);
125 d_add(dentry, inode);
131 * gfs2_link - Link to a file
132 * @old_dentry: The inode to link
133 * @dir: Add link to this directory
134 * @dentry: The name of the link
136 * Link the inode in "old_dentry" into the directory "dir" with the
142 static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
143 struct dentry *dentry)
145 struct gfs2_inode *dip = dir->u.generic_ip;
146 struct gfs2_sbd *sdp = dip->i_sbd;
147 struct inode *inode = old_dentry->d_inode;
148 struct gfs2_inode *ip = inode->u.generic_ip;
149 struct gfs2_holder ghs[2];
153 if (S_ISDIR(ip->i_di.di_mode))
156 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
157 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
159 error = gfs2_glock_nq_m(2, ghs);
163 error = gfs2_repermission(dir, MAY_WRITE | MAY_EXEC, NULL);
167 error = gfs2_dir_search(dir, &dentry->d_name, NULL, NULL);
178 if (!dip->i_di.di_nlink)
181 if (dip->i_di.di_entries == (uint32_t)-1)
184 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
187 if (!ip->i_di.di_nlink)
190 if (ip->i_di.di_nlink == (uint32_t)-1)
193 alloc_required = error = gfs2_diradd_alloc_required(dir, &dentry->d_name);
198 if (alloc_required) {
199 struct gfs2_alloc *al = gfs2_alloc_get(dip);
201 error = gfs2_quota_lock(dip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
205 error = gfs2_quota_check(dip, dip->i_di.di_uid,
210 al->al_requested = sdp->sd_max_dirres;
212 error = gfs2_inplace_reserve(dip);
216 error = gfs2_trans_begin(sdp,
218 al->al_rgd->rd_ri.ri_length +
219 2 * RES_DINODE + RES_STATFS +
224 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + RES_LEAF, 0);
229 error = gfs2_dir_add(dir, &dentry->d_name, &ip->i_num,
230 IF2DT(ip->i_di.di_mode));
234 error = gfs2_change_nlink(ip, +1);
241 gfs2_inplace_release(dip);
245 gfs2_quota_unlock(dip);
252 gfs2_glock_dq_m(2, ghs);
255 gfs2_holder_uninit(ghs);
256 gfs2_holder_uninit(ghs + 1);
259 atomic_inc(&inode->i_count);
260 d_instantiate(dentry, inode);
261 mark_inode_dirty(inode);
268 * gfs2_unlink - Unlink a file
269 * @dir: The inode of the directory containing the file to unlink
270 * @dentry: The file itself
272 * Unlink a file. Call gfs2_unlinki()
277 static int gfs2_unlink(struct inode *dir, struct dentry *dentry)
279 struct gfs2_inode *dip = dir->u.generic_ip;
280 struct gfs2_sbd *sdp = dip->i_sbd;
281 struct gfs2_inode *ip = dentry->d_inode->u.generic_ip;
282 struct gfs2_unlinked *ul;
283 struct gfs2_holder ghs[2];
286 error = gfs2_unlinked_get(sdp, &ul);
290 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
291 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
293 error = gfs2_glock_nq_m(2, ghs);
297 error = gfs2_unlink_ok(dip, &dentry->d_name, ip);
301 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + RES_LEAF +
306 error = gfs2_unlinki(dip, &dentry->d_name, ip,ul);
311 gfs2_glock_dq_m(2, ghs);
314 gfs2_holder_uninit(ghs);
315 gfs2_holder_uninit(ghs + 1);
317 gfs2_unlinked_put(sdp, ul);
323 * gfs2_symlink - Create a symlink
324 * @dir: The directory to create the symlink in
325 * @dentry: The dentry to put the symlink in
326 * @symname: The thing which the link points to
331 static int gfs2_symlink(struct inode *dir, struct dentry *dentry,
334 struct gfs2_inode *dip = dir->u.generic_ip, *ip;
335 struct gfs2_sbd *sdp = dip->i_sbd;
336 struct gfs2_holder ghs[2];
338 struct buffer_head *dibh;
342 /* Must be stuffed with a null terminator for gfs2_follow_link() */
343 size = strlen(symname);
344 if (size > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode) - 1)
345 return -ENAMETOOLONG;
347 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
349 inode = gfs2_createi(ghs, &dentry->d_name, S_IFLNK | S_IRWXUGO);
351 gfs2_holder_uninit(ghs);
352 return PTR_ERR(inode);
355 ip = ghs[1].gh_gl->gl_object;
357 ip->i_di.di_size = size;
359 error = gfs2_meta_inode_buffer(ip, &dibh);
361 if (!gfs2_assert_withdraw(sdp, !error)) {
362 gfs2_dinode_out(&ip->i_di, dibh->b_data);
363 memcpy(dibh->b_data + sizeof(struct gfs2_dinode), symname,
369 if (dip->i_alloc.al_rgd)
370 gfs2_inplace_release(dip);
371 gfs2_quota_unlock(dip);
374 gfs2_glock_dq_uninit_m(2, ghs);
376 d_instantiate(dentry, inode);
377 mark_inode_dirty(inode);
383 * gfs2_mkdir - Make a directory
384 * @dir: The parent directory of the new one
385 * @dentry: The dentry of the new directory
386 * @mode: The mode of the new directory
391 static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode)
393 struct gfs2_inode *dip = dir->u.generic_ip, *ip;
394 struct gfs2_sbd *sdp = dip->i_sbd;
395 struct gfs2_holder ghs[2];
397 struct buffer_head *dibh;
400 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
402 inode = gfs2_createi(ghs, &dentry->d_name, S_IFDIR | mode);
404 gfs2_holder_uninit(ghs);
405 return PTR_ERR(inode);
408 ip = ghs[1].gh_gl->gl_object;
410 ip->i_di.di_nlink = 2;
411 ip->i_di.di_size = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode);
412 ip->i_di.di_flags |= GFS2_DIF_JDATA;
413 ip->i_di.di_payload_format = GFS2_FORMAT_DE;
414 ip->i_di.di_entries = 2;
416 error = gfs2_meta_inode_buffer(ip, &dibh);
418 if (!gfs2_assert_withdraw(sdp, !error)) {
419 struct gfs2_dinode *di = (struct gfs2_dinode *)dibh->b_data;
420 struct gfs2_dirent *dent = (struct gfs2_dirent *)(di+1);
423 gfs2_str2qstr(&str, ".");
424 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
425 gfs2_qstr2dirent(&str, GFS2_DIRENT_SIZE(str.len), dent);
426 dent->de_inum = di->di_num; /* already GFS2 endian */
427 dent->de_type = DT_DIR;
428 di->di_entries = cpu_to_be32(1);
430 gfs2_str2qstr(&str, "..");
431 dent = (struct gfs2_dirent *)((char*)dent + GFS2_DIRENT_SIZE(1));
432 gfs2_qstr2dirent(&str, dibh->b_size - GFS2_DIRENT_SIZE(1) - sizeof(struct gfs2_dinode), dent);
434 gfs2_inum_out(&dip->i_num, (char *) &dent->de_inum);
435 dent->de_type = DT_DIR;
437 gfs2_dinode_out(&ip->i_di, (char *)di);
442 error = gfs2_change_nlink(dip, +1);
443 gfs2_assert_withdraw(sdp, !error); /* dip already pinned */
446 if (dip->i_alloc.al_rgd)
447 gfs2_inplace_release(dip);
448 gfs2_quota_unlock(dip);
451 gfs2_glock_dq_uninit_m(2, ghs);
453 d_instantiate(dentry, inode);
454 mark_inode_dirty(inode);
460 * gfs2_rmdir - Remove a directory
461 * @dir: The parent directory of the directory to be removed
462 * @dentry: The dentry of the directory to remove
464 * Remove a directory. Call gfs2_rmdiri()
469 static int gfs2_rmdir(struct inode *dir, struct dentry *dentry)
471 struct gfs2_inode *dip = dir->u.generic_ip;
472 struct gfs2_sbd *sdp = dip->i_sbd;
473 struct gfs2_inode *ip = dentry->d_inode->u.generic_ip;
474 struct gfs2_unlinked *ul;
475 struct gfs2_holder ghs[2];
478 error = gfs2_unlinked_get(sdp, &ul);
482 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
483 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
485 error = gfs2_glock_nq_m(2, ghs);
489 error = gfs2_unlink_ok(dip, &dentry->d_name, ip);
493 if (ip->i_di.di_entries < 2) {
494 if (gfs2_consist_inode(ip))
495 gfs2_dinode_print(&ip->i_di);
499 if (ip->i_di.di_entries > 2) {
504 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + 3 * RES_LEAF +
509 error = gfs2_rmdiri(dip, &dentry->d_name, ip, ul);
514 gfs2_glock_dq_m(2, ghs);
517 gfs2_holder_uninit(ghs);
518 gfs2_holder_uninit(ghs + 1);
520 gfs2_unlinked_put(sdp, ul);
526 * gfs2_mknod - Make a special file
527 * @dir: The directory in which the special file will reside
528 * @dentry: The dentry of the special file
529 * @mode: The mode of the special file
530 * @rdev: The device specification of the special file
534 static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode,
537 struct gfs2_inode *dip = dir->u.generic_ip, *ip;
538 struct gfs2_sbd *sdp = dip->i_sbd;
539 struct gfs2_holder ghs[2];
541 struct buffer_head *dibh;
542 uint32_t major = 0, minor = 0;
545 switch (mode & S_IFMT) {
558 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
560 inode = gfs2_createi(ghs, &dentry->d_name, mode);
562 gfs2_holder_uninit(ghs);
563 return PTR_ERR(inode);
566 ip = ghs[1].gh_gl->gl_object;
568 ip->i_di.di_major = major;
569 ip->i_di.di_minor = minor;
571 error = gfs2_meta_inode_buffer(ip, &dibh);
573 if (!gfs2_assert_withdraw(sdp, !error)) {
574 gfs2_dinode_out(&ip->i_di, dibh->b_data);
579 if (dip->i_alloc.al_rgd)
580 gfs2_inplace_release(dip);
581 gfs2_quota_unlock(dip);
584 gfs2_glock_dq_uninit_m(2, ghs);
586 d_instantiate(dentry, inode);
587 mark_inode_dirty(inode);
593 * gfs2_rename - Rename a file
594 * @odir: Parent directory of old file name
595 * @odentry: The old dentry of the file
596 * @ndir: Parent directory of new file name
597 * @ndentry: The new dentry of the file
602 static int gfs2_rename(struct inode *odir, struct dentry *odentry,
603 struct inode *ndir, struct dentry *ndentry)
605 struct gfs2_inode *odip = odir->u.generic_ip;
606 struct gfs2_inode *ndip = ndir->u.generic_ip;
607 struct gfs2_inode *ip = odentry->d_inode->u.generic_ip;
608 struct gfs2_inode *nip = NULL;
609 struct gfs2_sbd *sdp = odip->i_sbd;
610 struct gfs2_unlinked *ul;
611 struct gfs2_holder ghs[4], r_gh;
618 if (ndentry->d_inode) {
619 nip = ndentry->d_inode->u.generic_ip;
624 error = gfs2_unlinked_get(sdp, &ul);
628 /* Make sure we aren't trying to move a dirctory into it's subdir */
630 if (S_ISDIR(ip->i_di.di_mode) && odip != ndip) {
633 error = gfs2_glock_nq_init(sdp->sd_rename_gl,
639 error = gfs2_ok_to_move(ip, ndip);
644 gfs2_holder_init(odip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
645 gfs2_holder_init(ndip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
646 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 2);
650 gfs2_holder_init(nip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh++);
652 error = gfs2_glock_nq_m(num_gh, ghs);
656 /* Check out the old directory */
658 error = gfs2_unlink_ok(odip, &odentry->d_name, ip);
662 /* Check out the new directory */
665 error = gfs2_unlink_ok(ndip, &ndentry->d_name, nip);
669 if (S_ISDIR(nip->i_di.di_mode)) {
670 if (nip->i_di.di_entries < 2) {
671 if (gfs2_consist_inode(nip))
672 gfs2_dinode_print(&nip->i_di);
676 if (nip->i_di.di_entries > 2) {
682 error = gfs2_repermission(ndir, MAY_WRITE | MAY_EXEC, NULL);
686 error = gfs2_dir_search(ndir, &ndentry->d_name, NULL, NULL);
698 if (!ndip->i_di.di_nlink) {
702 if (ndip->i_di.di_entries == (uint32_t)-1) {
706 if (S_ISDIR(ip->i_di.di_mode) &&
707 ndip->i_di.di_nlink == (uint32_t)-1) {
714 /* Check out the dir to be renamed */
717 error = gfs2_repermission(odentry->d_inode, MAY_WRITE, NULL);
722 alloc_required = error = gfs2_diradd_alloc_required(ndir, &ndentry->d_name);
727 if (alloc_required) {
728 struct gfs2_alloc *al = gfs2_alloc_get(ndip);
730 error = gfs2_quota_lock(ndip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
734 error = gfs2_quota_check(ndip, ndip->i_di.di_uid,
739 al->al_requested = sdp->sd_max_dirres;
741 error = gfs2_inplace_reserve(ndip);
745 error = gfs2_trans_begin(sdp, sdp->sd_max_dirres +
746 al->al_rgd->rd_ri.ri_length +
747 4 * RES_DINODE + 4 * RES_LEAF +
748 RES_UNLINKED + RES_STATFS +
753 error = gfs2_trans_begin(sdp, 4 * RES_DINODE +
760 /* Remove the target file, if it exists */
763 if (S_ISDIR(nip->i_di.di_mode))
764 error = gfs2_rmdiri(ndip, &ndentry->d_name, nip, ul);
766 error = gfs2_unlinki(ndip, &ndentry->d_name, nip, ul);
773 gfs2_str2qstr(&name, "..");
775 error = gfs2_change_nlink(ndip, +1);
778 error = gfs2_change_nlink(odip, -1);
782 error = gfs2_dir_mvino(ip, &name, &ndip->i_num, DT_DIR);
786 struct buffer_head *dibh;
787 error = gfs2_meta_inode_buffer(ip, &dibh);
790 ip->i_di.di_ctime = get_seconds();
791 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
792 gfs2_dinode_out(&ip->i_di, dibh->b_data);
796 error = gfs2_dir_del(odip, &odentry->d_name);
800 error = gfs2_dir_add(ndir, &ndentry->d_name, &ip->i_num,
801 IF2DT(ip->i_di.di_mode));
810 gfs2_inplace_release(ndip);
814 gfs2_quota_unlock(ndip);
818 gfs2_alloc_put(ndip);
821 gfs2_glock_dq_m(num_gh, ghs);
824 for (x = 0; x < num_gh; x++)
825 gfs2_holder_uninit(ghs + x);
829 gfs2_glock_dq_uninit(&r_gh);
832 gfs2_unlinked_put(sdp, ul);
838 * gfs2_readlink - Read the value of a symlink
839 * @dentry: the symlink
840 * @buf: the buffer to read the symlink data into
841 * @size: the size of the buffer
846 static int gfs2_readlink(struct dentry *dentry, char __user *user_buf,
849 struct gfs2_inode *ip = dentry->d_inode->u.generic_ip;
850 char array[GFS2_FAST_NAME_SIZE], *buf = array;
851 unsigned int len = GFS2_FAST_NAME_SIZE;
854 error = gfs2_readlinki(ip, &buf, &len);
858 if (user_size > len - 1)
861 if (copy_to_user(user_buf, buf, user_size))
873 * gfs2_follow_link - Follow a symbolic link
874 * @dentry: The dentry of the link
875 * @nd: Data that we pass to vfs_follow_link()
877 * This can handle symlinks of any size. It is optimised for symlinks
878 * under GFS2_FAST_NAME_SIZE.
880 * Returns: 0 on success or error code
883 static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd)
885 struct gfs2_inode *ip = dentry->d_inode->u.generic_ip;
886 char array[GFS2_FAST_NAME_SIZE], *buf = array;
887 unsigned int len = GFS2_FAST_NAME_SIZE;
890 error = gfs2_readlinki(ip, &buf, &len);
892 error = vfs_follow_link(nd, buf);
897 return ERR_PTR(error);
904 * @nd: passed from Linux VFS, ignored by us
909 static int gfs2_permission(struct inode *inode, int mask, struct nameidata *nd)
911 struct gfs2_inode *ip = inode->u.generic_ip;
912 struct gfs2_holder i_gh;
915 if (ip->i_vn == ip->i_gl->gl_vn)
916 return generic_permission(inode, mask, gfs2_check_acl);
918 error = gfs2_glock_nq_init(ip->i_gl,
919 LM_ST_SHARED, LM_FLAG_ANY,
922 error = generic_permission(inode, mask, gfs2_check_acl_locked);
923 gfs2_glock_dq_uninit(&i_gh);
929 static int setattr_size(struct inode *inode, struct iattr *attr)
931 struct gfs2_inode *ip = inode->u.generic_ip;
934 if (attr->ia_size != ip->i_di.di_size) {
935 error = vmtruncate(inode, attr->ia_size);
940 error = gfs2_truncatei(ip, attr->ia_size);
947 static int setattr_chown(struct inode *inode, struct iattr *attr)
949 struct gfs2_inode *ip = inode->u.generic_ip;
950 struct gfs2_sbd *sdp = ip->i_sbd;
951 struct buffer_head *dibh;
952 uint32_t ouid, ogid, nuid, ngid;
955 ouid = ip->i_di.di_uid;
956 ogid = ip->i_di.di_gid;
960 if (!(attr->ia_valid & ATTR_UID) || ouid == nuid)
961 ouid = nuid = NO_QUOTA_CHANGE;
962 if (!(attr->ia_valid & ATTR_GID) || ogid == ngid)
963 ogid = ngid = NO_QUOTA_CHANGE;
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);
987 gfs2_inode_attr_out(ip);
989 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
990 gfs2_dinode_out(&ip->i_di, dibh->b_data);
993 if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) {
994 gfs2_quota_change(ip, -ip->i_di.di_blocks,
996 gfs2_quota_change(ip, ip->i_di.di_blocks,
1001 gfs2_trans_end(sdp);
1004 gfs2_quota_unlock(ip);
1013 * gfs2_setattr - Change attributes on an inode
1014 * @dentry: The dentry which is changing
1015 * @attr: The structure describing the change
1017 * The VFS layer wants to change one or more of an inodes attributes. Write
1018 * that change out to disk.
1023 static int gfs2_setattr(struct dentry *dentry, struct iattr *attr)
1025 struct inode *inode = dentry->d_inode;
1026 struct gfs2_inode *ip = inode->u.generic_ip;
1027 struct gfs2_holder i_gh;
1030 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh);
1035 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1038 error = inode_change_ok(inode, attr);
1042 if (attr->ia_valid & ATTR_SIZE)
1043 error = setattr_size(inode, attr);
1044 else if (attr->ia_valid & (ATTR_UID | ATTR_GID))
1045 error = setattr_chown(inode, attr);
1046 else if ((attr->ia_valid & ATTR_MODE) && IS_POSIXACL(inode))
1047 error = gfs2_acl_chmod(ip, attr);
1049 error = gfs2_setattr_simple(ip, attr);
1052 gfs2_glock_dq_uninit(&i_gh);
1055 mark_inode_dirty(inode);
1061 * gfs2_getattr - Read out an inode's attributes
1063 * @dentry: The dentry to stat
1064 * @stat: The inode's stats
1069 static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry,
1072 struct inode *inode = dentry->d_inode;
1073 struct gfs2_inode *ip = inode->u.generic_ip;
1074 struct gfs2_holder gh;
1077 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
1079 generic_fillattr(inode, stat);
1080 gfs2_glock_dq_uninit(&gh);
1086 static int gfs2_setxattr(struct dentry *dentry, const char *name,
1087 const void *data, size_t size, int flags)
1089 struct gfs2_inode *ip = dentry->d_inode->u.generic_ip;
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_data = (char *)data;
1097 er.er_name_len = strlen(er.er_name);
1098 er.er_data_len = size;
1099 er.er_flags = flags;
1101 gfs2_assert_warn(ip->i_sbd, !(er.er_flags & GFS2_ERF_MODE));
1103 return gfs2_ea_set(ip, &er);
1106 static ssize_t gfs2_getxattr(struct dentry *dentry, const char *name,
1107 void *data, size_t size)
1109 struct gfs2_ea_request er;
1111 memset(&er, 0, sizeof(struct gfs2_ea_request));
1112 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1113 if (er.er_type == GFS2_EATYPE_UNUSED)
1116 er.er_name_len = strlen(er.er_name);
1117 er.er_data_len = size;
1119 return gfs2_ea_get(dentry->d_inode->u.generic_ip, &er);
1122 static ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size)
1124 struct gfs2_ea_request er;
1126 memset(&er, 0, sizeof(struct gfs2_ea_request));
1127 er.er_data = (size) ? buffer : NULL;
1128 er.er_data_len = size;
1130 return gfs2_ea_list(dentry->d_inode->u.generic_ip, &er);
1133 static int gfs2_removexattr(struct dentry *dentry, const char *name)
1135 struct gfs2_ea_request er;
1137 memset(&er, 0, sizeof(struct gfs2_ea_request));
1138 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1139 if (er.er_type == GFS2_EATYPE_UNUSED)
1141 er.er_name_len = strlen(er.er_name);
1143 return gfs2_ea_remove(dentry->d_inode->u.generic_ip, &er);
1146 struct inode_operations gfs2_file_iops = {
1147 .permission = gfs2_permission,
1148 .setattr = gfs2_setattr,
1149 .getattr = gfs2_getattr,
1150 .setxattr = gfs2_setxattr,
1151 .getxattr = gfs2_getxattr,
1152 .listxattr = gfs2_listxattr,
1153 .removexattr = gfs2_removexattr,
1156 struct inode_operations gfs2_dev_iops = {
1157 .permission = gfs2_permission,
1158 .setattr = gfs2_setattr,
1159 .getattr = gfs2_getattr,
1160 .setxattr = gfs2_setxattr,
1161 .getxattr = gfs2_getxattr,
1162 .listxattr = gfs2_listxattr,
1163 .removexattr = gfs2_removexattr,
1166 struct inode_operations gfs2_dir_iops = {
1167 .create = gfs2_create,
1168 .lookup = gfs2_lookup,
1170 .unlink = gfs2_unlink,
1171 .symlink = gfs2_symlink,
1172 .mkdir = gfs2_mkdir,
1173 .rmdir = gfs2_rmdir,
1174 .mknod = gfs2_mknod,
1175 .rename = gfs2_rename,
1176 .permission = gfs2_permission,
1177 .setattr = gfs2_setattr,
1178 .getattr = gfs2_getattr,
1179 .setxattr = gfs2_setxattr,
1180 .getxattr = gfs2_getxattr,
1181 .listxattr = gfs2_listxattr,
1182 .removexattr = gfs2_removexattr,
1185 struct inode_operations gfs2_symlink_iops = {
1186 .readlink = gfs2_readlink,
1187 .follow_link = gfs2_follow_link,
1188 .permission = gfs2_permission,
1189 .setattr = gfs2_setattr,
1190 .getattr = gfs2_getattr,
1191 .setxattr = gfs2_setxattr,
1192 .getxattr = gfs2_getxattr,
1193 .listxattr = gfs2_listxattr,
1194 .removexattr = gfs2_removexattr,