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 <asm/semaphore.h>
21 #include <asm/uaccess.h>
32 #include "ops_dentry.h"
33 #include "ops_inode.h"
41 * gfs2_create - Create a file
42 * @dir: The directory in which to create the file
43 * @dentry: The dentry of the new file
44 * @mode: The mode of the new file
49 static int gfs2_create(struct inode *dir, struct dentry *dentry,
50 int mode, struct nameidata *nd)
52 struct gfs2_inode *dip = get_v2ip(dir);
53 struct gfs2_sbd *sdp = dip->i_sbd;
54 struct gfs2_holder ghs[2];
59 atomic_inc(&sdp->sd_ops_inode);
61 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
64 inode = gfs2_createi(ghs, &dentry->d_name, S_IFREG | mode);
67 if (dip->i_alloc.al_rgd)
68 gfs2_inplace_release(dip);
69 gfs2_quota_unlock(dip);
71 gfs2_glock_dq_uninit_m(2, ghs);
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 error = gfs2_lookupi(dir, &dentry->d_name, 0, &inode);
82 gfs2_holder_uninit(ghs);
84 } else if (error != -ENOENT) {
85 gfs2_holder_uninit(ghs);
90 d_instantiate(dentry, inode);
92 mark_inode_dirty(inode);
98 * gfs2_lookup - Look up a filename in a directory and return its inode
99 * @dir: The directory inode
100 * @dentry: The dentry of the new inode
101 * @nd: passed from Linux VFS, ignored by us
103 * Called by the VFS layer. Lock dir and call gfs2_lookupi()
108 static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry,
109 struct nameidata *nd)
111 struct gfs2_inode *dip = get_v2ip(dir);
112 struct gfs2_sbd *sdp = dip->i_sbd;
113 struct inode *inode = NULL;
116 atomic_inc(&sdp->sd_ops_inode);
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 = get_v2ip(dir);
148 struct gfs2_sbd *sdp = dip->i_sbd;
149 struct inode *inode = old_dentry->d_inode;
150 struct gfs2_inode *ip = get_v2ip(inode);
151 struct gfs2_holder ghs[2];
155 atomic_inc(&sdp->sd_ops_inode);
157 if (S_ISDIR(ip->i_di.di_mode))
160 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
161 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
163 error = gfs2_glock_nq_m(2, ghs);
167 error = gfs2_repermission(dir, MAY_WRITE | MAY_EXEC, NULL);
171 error = gfs2_dir_search(dip, &dentry->d_name, NULL, NULL);
182 if (!dip->i_di.di_nlink)
185 if (dip->i_di.di_entries == (uint32_t)-1)
188 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
191 if (!ip->i_di.di_nlink)
194 if (ip->i_di.di_nlink == (uint32_t)-1)
197 error = gfs2_diradd_alloc_required(dip, &dentry->d_name,
202 if (alloc_required) {
203 struct gfs2_alloc *al = gfs2_alloc_get(dip);
205 error = gfs2_quota_lock(dip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
209 error = gfs2_quota_check(dip, dip->i_di.di_uid,
214 al->al_requested = sdp->sd_max_dirres;
216 error = gfs2_inplace_reserve(dip);
220 error = gfs2_trans_begin(sdp,
222 al->al_rgd->rd_ri.ri_length +
223 2 * RES_DINODE + RES_STATFS +
228 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + RES_LEAF, 0);
233 error = gfs2_dir_add(dip, &dentry->d_name, &ip->i_num,
234 IF2DT(ip->i_di.di_mode));
238 error = gfs2_change_nlink(ip, +1);
245 gfs2_inplace_release(dip);
249 gfs2_quota_unlock(dip);
256 gfs2_glock_dq_m(2, ghs);
259 gfs2_holder_uninit(ghs);
260 gfs2_holder_uninit(ghs + 1);
263 atomic_inc(&inode->i_count);
264 d_instantiate(dentry, inode);
265 mark_inode_dirty(inode);
272 * gfs2_unlink - Unlink a file
273 * @dir: The inode of the directory containing the file to unlink
274 * @dentry: The file itself
276 * Unlink a file. Call gfs2_unlinki()
281 static int gfs2_unlink(struct inode *dir, struct dentry *dentry)
283 struct gfs2_inode *dip = get_v2ip(dir);
284 struct gfs2_sbd *sdp = dip->i_sbd;
285 struct gfs2_inode *ip = get_v2ip(dentry->d_inode);
286 struct gfs2_unlinked *ul;
287 struct gfs2_holder ghs[2];
290 atomic_inc(&sdp->sd_ops_inode);
292 error = gfs2_unlinked_get(sdp, &ul);
296 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
297 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
299 error = gfs2_glock_nq_m(2, ghs);
303 error = gfs2_unlink_ok(dip, &dentry->d_name, ip);
307 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + RES_LEAF +
312 error = gfs2_unlinki(dip, &dentry->d_name, ip,ul);
317 gfs2_glock_dq_m(2, ghs);
320 gfs2_holder_uninit(ghs);
321 gfs2_holder_uninit(ghs + 1);
323 gfs2_unlinked_put(sdp, ul);
329 * gfs2_symlink - Create a symlink
330 * @dir: The directory to create the symlink in
331 * @dentry: The dentry to put the symlink in
332 * @symname: The thing which the link points to
337 static int gfs2_symlink(struct inode *dir, struct dentry *dentry,
340 struct gfs2_inode *dip = get_v2ip(dir), *ip;
341 struct gfs2_sbd *sdp = dip->i_sbd;
342 struct gfs2_holder ghs[2];
344 struct buffer_head *dibh;
348 atomic_inc(&sdp->sd_ops_inode);
350 /* Must be stuffed with a null terminator for gfs2_follow_link() */
351 size = strlen(symname);
352 if (size > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode) - 1)
353 return -ENAMETOOLONG;
355 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
357 inode = gfs2_createi(ghs, &dentry->d_name, S_IFLNK | S_IRWXUGO);
359 gfs2_holder_uninit(ghs);
360 return PTR_ERR(inode);
363 ip = get_gl2ip(ghs[1].gh_gl);
365 ip->i_di.di_size = size;
367 error = gfs2_meta_inode_buffer(ip, &dibh);
369 if (!gfs2_assert_withdraw(sdp, !error)) {
370 gfs2_dinode_out(&ip->i_di, dibh->b_data);
371 memcpy(dibh->b_data + sizeof(struct gfs2_dinode), symname,
377 if (dip->i_alloc.al_rgd)
378 gfs2_inplace_release(dip);
379 gfs2_quota_unlock(dip);
382 gfs2_glock_dq_uninit_m(2, ghs);
384 d_instantiate(dentry, inode);
385 mark_inode_dirty(inode);
391 * gfs2_mkdir - Make a directory
392 * @dir: The parent directory of the new one
393 * @dentry: The dentry of the new directory
394 * @mode: The mode of the new directory
399 static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode)
401 struct gfs2_inode *dip = get_v2ip(dir), *ip;
402 struct gfs2_sbd *sdp = dip->i_sbd;
403 struct gfs2_holder ghs[2];
405 struct buffer_head *dibh;
408 atomic_inc(&sdp->sd_ops_inode);
410 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
412 inode = gfs2_createi(ghs, &dentry->d_name, S_IFDIR | mode);
414 gfs2_holder_uninit(ghs);
415 return PTR_ERR(inode);
418 ip = get_gl2ip(ghs[1].gh_gl);
420 ip->i_di.di_nlink = 2;
421 ip->i_di.di_size = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode);
422 ip->i_di.di_flags |= GFS2_DIF_JDATA;
423 ip->i_di.di_payload_format = GFS2_FORMAT_DE;
424 ip->i_di.di_entries = 2;
426 error = gfs2_meta_inode_buffer(ip, &dibh);
428 if (!gfs2_assert_withdraw(sdp, !error)) {
429 struct gfs2_dinode *di = (struct gfs2_dinode *)dibh->b_data;
430 struct gfs2_dirent *dent;
432 gfs2_dirent_alloc(ip, dibh, 1, &dent);
434 dent->de_inum = di->di_num; /* already GFS2 endian */
435 dent->de_hash = gfs2_disk_hash(".", 1);
436 dent->de_hash = cpu_to_be32(dent->de_hash);
437 dent->de_type = DT_DIR;
438 memcpy((char *) (dent + 1), ".", 1);
439 di->di_entries = cpu_to_be32(1);
441 gfs2_dirent_alloc(ip, dibh, 2, &dent);
443 gfs2_inum_out(&dip->i_num, (char *) &dent->de_inum);
444 dent->de_hash = gfs2_disk_hash("..", 2);
445 dent->de_hash = cpu_to_be32(dent->de_hash);
446 dent->de_type = DT_DIR;
447 memcpy((char *) (dent + 1), "..", 2);
449 gfs2_dinode_out(&ip->i_di, (char *)di);
454 error = gfs2_change_nlink(dip, +1);
455 gfs2_assert_withdraw(sdp, !error); /* dip already pinned */
458 if (dip->i_alloc.al_rgd)
459 gfs2_inplace_release(dip);
460 gfs2_quota_unlock(dip);
463 gfs2_glock_dq_uninit_m(2, ghs);
465 d_instantiate(dentry, inode);
466 mark_inode_dirty(inode);
472 * gfs2_rmdir - Remove a directory
473 * @dir: The parent directory of the directory to be removed
474 * @dentry: The dentry of the directory to remove
476 * Remove a directory. Call gfs2_rmdiri()
481 static int gfs2_rmdir(struct inode *dir, struct dentry *dentry)
483 struct gfs2_inode *dip = get_v2ip(dir);
484 struct gfs2_sbd *sdp = dip->i_sbd;
485 struct gfs2_inode *ip = get_v2ip(dentry->d_inode);
486 struct gfs2_unlinked *ul;
487 struct gfs2_holder ghs[2];
490 atomic_inc(&sdp->sd_ops_inode);
492 error = gfs2_unlinked_get(sdp, &ul);
496 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
497 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
499 error = gfs2_glock_nq_m(2, ghs);
503 error = gfs2_unlink_ok(dip, &dentry->d_name, ip);
507 if (ip->i_di.di_entries < 2) {
508 if (gfs2_consist_inode(ip))
509 gfs2_dinode_print(&ip->i_di);
513 if (ip->i_di.di_entries > 2) {
518 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + 3 * RES_LEAF +
523 error = gfs2_rmdiri(dip, &dentry->d_name, ip, ul);
528 gfs2_glock_dq_m(2, ghs);
531 gfs2_holder_uninit(ghs);
532 gfs2_holder_uninit(ghs + 1);
534 gfs2_unlinked_put(sdp, ul);
540 * gfs2_mknod - Make a special file
541 * @dir: The directory in which the special file will reside
542 * @dentry: The dentry of the special file
543 * @mode: The mode of the special file
544 * @rdev: The device specification of the special file
548 static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode,
551 struct gfs2_inode *dip = get_v2ip(dir), *ip;
552 struct gfs2_sbd *sdp = dip->i_sbd;
553 struct gfs2_holder ghs[2];
555 struct buffer_head *dibh;
556 uint32_t major = 0, minor = 0;
559 atomic_inc(&sdp->sd_ops_inode);
561 switch (mode & S_IFMT) {
574 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
576 inode = gfs2_createi(ghs, &dentry->d_name, mode);
578 gfs2_holder_uninit(ghs);
579 return PTR_ERR(inode);
582 ip = get_gl2ip(ghs[1].gh_gl);
584 ip->i_di.di_major = major;
585 ip->i_di.di_minor = minor;
587 error = gfs2_meta_inode_buffer(ip, &dibh);
589 if (!gfs2_assert_withdraw(sdp, !error)) {
590 gfs2_dinode_out(&ip->i_di, dibh->b_data);
595 if (dip->i_alloc.al_rgd)
596 gfs2_inplace_release(dip);
597 gfs2_quota_unlock(dip);
600 gfs2_glock_dq_uninit_m(2, ghs);
602 d_instantiate(dentry, inode);
603 mark_inode_dirty(inode);
609 * gfs2_rename - Rename a file
610 * @odir: Parent directory of old file name
611 * @odentry: The old dentry of the file
612 * @ndir: Parent directory of new file name
613 * @ndentry: The new dentry of the file
618 static int gfs2_rename(struct inode *odir, struct dentry *odentry,
619 struct inode *ndir, struct dentry *ndentry)
621 struct gfs2_inode *odip = get_v2ip(odir);
622 struct gfs2_inode *ndip = get_v2ip(ndir);
623 struct gfs2_inode *ip = get_v2ip(odentry->d_inode);
624 struct gfs2_inode *nip = NULL;
625 struct gfs2_sbd *sdp = odip->i_sbd;
626 struct gfs2_unlinked *ul;
627 struct gfs2_holder ghs[4], r_gh;
634 atomic_inc(&sdp->sd_ops_inode);
636 if (ndentry->d_inode) {
637 nip = get_v2ip(ndentry->d_inode);
642 error = gfs2_unlinked_get(sdp, &ul);
646 /* Make sure we aren't trying to move a dirctory into it's subdir */
648 if (S_ISDIR(ip->i_di.di_mode) && odip != ndip) {
651 error = gfs2_glock_nq_init(sdp->sd_rename_gl,
657 error = gfs2_ok_to_move(ip, ndip);
662 gfs2_holder_init(odip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
663 gfs2_holder_init(ndip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
664 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 2);
668 gfs2_holder_init(nip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh++);
670 error = gfs2_glock_nq_m(num_gh, ghs);
674 /* Check out the old directory */
676 error = gfs2_unlink_ok(odip, &odentry->d_name, ip);
680 /* Check out the new directory */
683 error = gfs2_unlink_ok(ndip, &ndentry->d_name, nip);
687 if (S_ISDIR(nip->i_di.di_mode)) {
688 if (nip->i_di.di_entries < 2) {
689 if (gfs2_consist_inode(nip))
690 gfs2_dinode_print(&nip->i_di);
694 if (nip->i_di.di_entries > 2) {
700 error = gfs2_repermission(ndir, MAY_WRITE | MAY_EXEC, NULL);
704 error = gfs2_dir_search(ndip, &ndentry->d_name, NULL, NULL);
716 if (!ndip->i_di.di_nlink) {
720 if (ndip->i_di.di_entries == (uint32_t)-1) {
724 if (S_ISDIR(ip->i_di.di_mode) &&
725 ndip->i_di.di_nlink == (uint32_t)-1) {
732 /* Check out the dir to be renamed */
735 error = gfs2_repermission(odentry->d_inode, MAY_WRITE, NULL);
740 error = gfs2_diradd_alloc_required(ndip, &ndentry->d_name,
745 if (alloc_required) {
746 struct gfs2_alloc *al = gfs2_alloc_get(ndip);
748 error = gfs2_quota_lock(ndip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
752 error = gfs2_quota_check(ndip, ndip->i_di.di_uid,
757 al->al_requested = sdp->sd_max_dirres;
759 error = gfs2_inplace_reserve(ndip);
763 error = gfs2_trans_begin(sdp,
765 al->al_rgd->rd_ri.ri_length +
766 4 * RES_DINODE + 4 * RES_LEAF +
767 RES_UNLINKED + RES_STATFS +
772 error = gfs2_trans_begin(sdp, 4 * RES_DINODE +
779 /* Remove the target file, if it exists */
782 if (S_ISDIR(nip->i_di.di_mode))
783 error = gfs2_rmdiri(ndip, &ndentry->d_name, nip, ul);
785 error = gfs2_unlinki(ndip, &ndentry->d_name, nip, ul);
795 error = gfs2_change_nlink(ndip, +1);
798 error = gfs2_change_nlink(odip, -1);
802 error = gfs2_dir_mvino(ip, &name, &ndip->i_num, DT_DIR);
806 struct buffer_head *dibh;
807 error = gfs2_meta_inode_buffer(ip, &dibh);
810 ip->i_di.di_ctime = get_seconds();
811 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
812 gfs2_dinode_out(&ip->i_di, dibh->b_data);
816 error = gfs2_dir_del(odip, &odentry->d_name);
820 error = gfs2_dir_add(ndip, &ndentry->d_name, &ip->i_num,
821 IF2DT(ip->i_di.di_mode));
830 gfs2_inplace_release(ndip);
834 gfs2_quota_unlock(ndip);
838 gfs2_alloc_put(ndip);
841 gfs2_glock_dq_m(num_gh, ghs);
844 for (x = 0; x < num_gh; x++)
845 gfs2_holder_uninit(ghs + x);
849 gfs2_glock_dq_uninit(&r_gh);
852 gfs2_unlinked_put(sdp, ul);
858 * gfs2_readlink - Read the value of a symlink
859 * @dentry: the symlink
860 * @buf: the buffer to read the symlink data into
861 * @size: the size of the buffer
866 static int gfs2_readlink(struct dentry *dentry, char __user *user_buf,
869 struct gfs2_inode *ip = get_v2ip(dentry->d_inode);
870 char array[GFS2_FAST_NAME_SIZE], *buf = array;
871 unsigned int len = GFS2_FAST_NAME_SIZE;
874 atomic_inc(&ip->i_sbd->sd_ops_inode);
876 error = gfs2_readlinki(ip, &buf, &len);
880 if (user_size > len - 1)
883 if (copy_to_user(user_buf, buf, user_size))
895 * gfs2_follow_link - Follow a symbolic link
896 * @dentry: The dentry of the link
897 * @nd: Data that we pass to vfs_follow_link()
899 * This can handle symlinks of any size. It is optimised for symlinks
900 * under GFS2_FAST_NAME_SIZE.
902 * Returns: 0 on success or error code
905 static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd)
907 struct gfs2_inode *ip = get_v2ip(dentry->d_inode);
908 char array[GFS2_FAST_NAME_SIZE], *buf = array;
909 unsigned int len = GFS2_FAST_NAME_SIZE;
912 atomic_inc(&ip->i_sbd->sd_ops_inode);
914 error = gfs2_readlinki(ip, &buf, &len);
916 error = vfs_follow_link(nd, buf);
921 return ERR_PTR(error);
928 * @nd: passed from Linux VFS, ignored by us
933 static int gfs2_permission(struct inode *inode, int mask, struct nameidata *nd)
935 struct gfs2_inode *ip = get_v2ip(inode);
936 struct gfs2_holder i_gh;
939 atomic_inc(&ip->i_sbd->sd_ops_inode);
941 if (ip->i_vn == ip->i_gl->gl_vn)
942 return generic_permission(inode, mask, gfs2_check_acl);
944 error = gfs2_glock_nq_init(ip->i_gl,
945 LM_ST_SHARED, LM_FLAG_ANY,
948 error = generic_permission(inode, mask, gfs2_check_acl_locked);
949 gfs2_glock_dq_uninit(&i_gh);
955 static int setattr_size(struct inode *inode, struct iattr *attr)
957 struct gfs2_inode *ip = get_v2ip(inode);
960 if (attr->ia_size != ip->i_di.di_size) {
961 error = vmtruncate(inode, attr->ia_size);
966 error = gfs2_truncatei(ip, attr->ia_size);
973 static int setattr_chown(struct inode *inode, struct iattr *attr)
975 struct gfs2_inode *ip = get_v2ip(inode);
976 struct gfs2_sbd *sdp = ip->i_sbd;
977 struct buffer_head *dibh;
978 uint32_t ouid, ogid, nuid, ngid;
981 ouid = ip->i_di.di_uid;
982 ogid = ip->i_di.di_gid;
986 if (!(attr->ia_valid & ATTR_UID) || ouid == nuid)
987 ouid = nuid = NO_QUOTA_CHANGE;
988 if (!(attr->ia_valid & ATTR_GID) || ogid == ngid)
989 ogid = ngid = NO_QUOTA_CHANGE;
993 error = gfs2_quota_lock(ip, nuid, ngid);
997 if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) {
998 error = gfs2_quota_check(ip, nuid, ngid);
1003 error = gfs2_trans_begin(sdp, RES_DINODE + 2 * RES_QUOTA, 0);
1007 error = gfs2_meta_inode_buffer(ip, &dibh);
1011 error = inode_setattr(inode, attr);
1012 gfs2_assert_warn(sdp, !error);
1013 gfs2_inode_attr_out(ip);
1015 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
1016 gfs2_dinode_out(&ip->i_di, dibh->b_data);
1019 if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) {
1020 gfs2_quota_change(ip, -ip->i_di.di_blocks,
1022 gfs2_quota_change(ip, ip->i_di.di_blocks,
1027 gfs2_trans_end(sdp);
1030 gfs2_quota_unlock(ip);
1039 * gfs2_setattr - Change attributes on an inode
1040 * @dentry: The dentry which is changing
1041 * @attr: The structure describing the change
1043 * The VFS layer wants to change one or more of an inodes attributes. Write
1044 * that change out to disk.
1049 static int gfs2_setattr(struct dentry *dentry, struct iattr *attr)
1051 struct inode *inode = dentry->d_inode;
1052 struct gfs2_inode *ip = get_v2ip(inode);
1053 struct gfs2_holder i_gh;
1056 atomic_inc(&ip->i_sbd->sd_ops_inode);
1058 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh);
1063 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1066 error = inode_change_ok(inode, attr);
1070 if (attr->ia_valid & ATTR_SIZE)
1071 error = setattr_size(inode, attr);
1072 else if (attr->ia_valid & (ATTR_UID | ATTR_GID))
1073 error = setattr_chown(inode, attr);
1074 else if ((attr->ia_valid & ATTR_MODE) && IS_POSIXACL(inode))
1075 error = gfs2_acl_chmod(ip, attr);
1077 error = gfs2_setattr_simple(ip, attr);
1080 gfs2_glock_dq_uninit(&i_gh);
1083 mark_inode_dirty(inode);
1089 * gfs2_getattr - Read out an inode's attributes
1091 * @dentry: The dentry to stat
1092 * @stat: The inode's stats
1097 static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry,
1100 struct inode *inode = dentry->d_inode;
1101 struct gfs2_inode *ip = get_v2ip(inode);
1102 struct gfs2_holder gh;
1105 atomic_inc(&ip->i_sbd->sd_ops_inode);
1107 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
1109 generic_fillattr(inode, stat);
1110 gfs2_glock_dq_uninit(&gh);
1116 static int gfs2_setxattr(struct dentry *dentry, const char *name,
1117 const void *data, size_t size, int flags)
1119 struct gfs2_inode *ip = get_v2ip(dentry->d_inode);
1120 struct gfs2_ea_request er;
1122 atomic_inc(&ip->i_sbd->sd_ops_inode);
1124 memset(&er, 0, sizeof(struct gfs2_ea_request));
1125 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1126 if (er.er_type == GFS2_EATYPE_UNUSED)
1128 er.er_data = (char *)data;
1129 er.er_name_len = strlen(er.er_name);
1130 er.er_data_len = size;
1131 er.er_flags = flags;
1133 gfs2_assert_warn(ip->i_sbd, !(er.er_flags & GFS2_ERF_MODE));
1135 return gfs2_ea_set(ip, &er);
1138 static ssize_t gfs2_getxattr(struct dentry *dentry, const char *name,
1139 void *data, size_t size)
1141 struct gfs2_ea_request er;
1143 atomic_inc(&get_v2sdp(dentry->d_inode->i_sb)->sd_ops_inode);
1145 memset(&er, 0, sizeof(struct gfs2_ea_request));
1146 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1147 if (er.er_type == GFS2_EATYPE_UNUSED)
1150 er.er_name_len = strlen(er.er_name);
1151 er.er_data_len = size;
1153 return gfs2_ea_get(get_v2ip(dentry->d_inode), &er);
1156 static ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size)
1158 struct gfs2_ea_request er;
1160 atomic_inc(&get_v2sdp(dentry->d_inode->i_sb)->sd_ops_inode);
1162 memset(&er, 0, sizeof(struct gfs2_ea_request));
1163 er.er_data = (size) ? buffer : NULL;
1164 er.er_data_len = size;
1166 return gfs2_ea_list(get_v2ip(dentry->d_inode), &er);
1169 static int gfs2_removexattr(struct dentry *dentry, const char *name)
1171 struct gfs2_ea_request er;
1173 atomic_inc(&get_v2sdp(dentry->d_inode->i_sb)->sd_ops_inode);
1175 memset(&er, 0, sizeof(struct gfs2_ea_request));
1176 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1177 if (er.er_type == GFS2_EATYPE_UNUSED)
1179 er.er_name_len = strlen(er.er_name);
1181 return gfs2_ea_remove(get_v2ip(dentry->d_inode), &er);
1184 struct inode_operations gfs2_file_iops = {
1185 .permission = gfs2_permission,
1186 .setattr = gfs2_setattr,
1187 .getattr = gfs2_getattr,
1188 .setxattr = gfs2_setxattr,
1189 .getxattr = gfs2_getxattr,
1190 .listxattr = gfs2_listxattr,
1191 .removexattr = gfs2_removexattr,
1194 struct inode_operations gfs2_dev_iops = {
1195 .permission = gfs2_permission,
1196 .setattr = gfs2_setattr,
1197 .getattr = gfs2_getattr,
1198 .setxattr = gfs2_setxattr,
1199 .getxattr = gfs2_getxattr,
1200 .listxattr = gfs2_listxattr,
1201 .removexattr = gfs2_removexattr,
1204 struct inode_operations gfs2_dir_iops = {
1205 .create = gfs2_create,
1206 .lookup = gfs2_lookup,
1208 .unlink = gfs2_unlink,
1209 .symlink = gfs2_symlink,
1210 .mkdir = gfs2_mkdir,
1211 .rmdir = gfs2_rmdir,
1212 .mknod = gfs2_mknod,
1213 .rename = gfs2_rename,
1214 .permission = gfs2_permission,
1215 .setattr = gfs2_setattr,
1216 .getattr = gfs2_getattr,
1217 .setxattr = gfs2_setxattr,
1218 .getxattr = gfs2_getxattr,
1219 .listxattr = gfs2_listxattr,
1220 .removexattr = gfs2_removexattr,
1223 struct inode_operations gfs2_symlink_iops = {
1224 .readlink = gfs2_readlink,
1225 .follow_link = gfs2_follow_link,
1226 .permission = gfs2_permission,
1227 .setattr = gfs2_setattr,
1228 .getattr = gfs2_getattr,
1229 .setxattr = gfs2_setxattr,
1230 .getxattr = gfs2_getxattr,
1231 .listxattr = gfs2_listxattr,
1232 .removexattr = gfs2_removexattr,