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), *ip;
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 error = gfs2_createi(ghs, &dentry->d_name, S_IFREG | mode);
66 ip = get_gl2ip(ghs[1].gh_gl);
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 (error != -EEXIST ||
75 (nd->intent.open.flags & O_EXCL)) {
76 gfs2_holder_uninit(ghs);
80 error = gfs2_lookupi(dip, &dentry->d_name, 0, &ip);
83 gfs2_holder_uninit(ghs);
85 } else if (error != -ENOENT) {
86 gfs2_holder_uninit(ghs);
91 inode = gfs2_ip2v(ip);
97 d_instantiate(dentry, inode);
99 mark_inode_dirty(inode);
105 * gfs2_lookup - Look up a filename in a directory and return its inode
106 * @dir: The directory inode
107 * @dentry: The dentry of the new inode
108 * @nd: passed from Linux VFS, ignored by us
110 * Called by the VFS layer. Lock dir and call gfs2_lookupi()
115 static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry,
116 struct nameidata *nd)
118 struct gfs2_inode *dip = get_v2ip(dir), *ip;
119 struct gfs2_sbd *sdp = dip->i_sbd;
120 struct inode *inode = NULL;
123 atomic_inc(&sdp->sd_ops_inode);
125 if (!sdp->sd_args.ar_localcaching)
126 dentry->d_op = &gfs2_dops;
128 error = gfs2_lookupi(dip, &dentry->d_name, 0, &ip);
130 inode = gfs2_ip2v(ip);
133 return ERR_PTR(-ENOMEM);
135 } else if (error != -ENOENT)
136 return ERR_PTR(error);
139 return d_splice_alias(inode, dentry);
140 d_add(dentry, inode);
146 * gfs2_link - Link to a file
147 * @old_dentry: The inode to link
148 * @dir: Add link to this directory
149 * @dentry: The name of the link
151 * Link the inode in "old_dentry" into the directory "dir" with the
157 static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
158 struct dentry *dentry)
160 struct gfs2_inode *dip = get_v2ip(dir);
161 struct gfs2_sbd *sdp = dip->i_sbd;
162 struct inode *inode = old_dentry->d_inode;
163 struct gfs2_inode *ip = get_v2ip(inode);
164 struct gfs2_holder ghs[2];
168 atomic_inc(&sdp->sd_ops_inode);
170 if (S_ISDIR(ip->i_di.di_mode))
173 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
174 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
176 error = gfs2_glock_nq_m(2, ghs);
180 error = gfs2_repermission(dir, MAY_WRITE | MAY_EXEC, NULL);
184 error = gfs2_dir_search(dip, &dentry->d_name, NULL, NULL);
195 if (!dip->i_di.di_nlink)
198 if (dip->i_di.di_entries == (uint32_t)-1)
201 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
204 if (!ip->i_di.di_nlink)
207 if (ip->i_di.di_nlink == (uint32_t)-1)
210 error = gfs2_diradd_alloc_required(dip, &dentry->d_name,
215 if (alloc_required) {
216 struct gfs2_alloc *al = gfs2_alloc_get(dip);
218 error = gfs2_quota_lock(dip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
222 error = gfs2_quota_check(dip, dip->i_di.di_uid,
227 al->al_requested = sdp->sd_max_dirres;
229 error = gfs2_inplace_reserve(dip);
233 error = gfs2_trans_begin(sdp,
235 al->al_rgd->rd_ri.ri_length +
236 2 * RES_DINODE + RES_STATFS +
241 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + RES_LEAF, 0);
246 error = gfs2_dir_add(dip, &dentry->d_name, &ip->i_num,
247 IF2DT(ip->i_di.di_mode));
251 error = gfs2_change_nlink(ip, +1);
258 gfs2_inplace_release(dip);
262 gfs2_quota_unlock(dip);
269 gfs2_glock_dq_m(2, ghs);
272 gfs2_holder_uninit(ghs);
273 gfs2_holder_uninit(ghs + 1);
276 atomic_inc(&inode->i_count);
277 d_instantiate(dentry, inode);
278 mark_inode_dirty(inode);
285 * gfs2_unlink - Unlink a file
286 * @dir: The inode of the directory containing the file to unlink
287 * @dentry: The file itself
289 * Unlink a file. Call gfs2_unlinki()
294 static int gfs2_unlink(struct inode *dir, struct dentry *dentry)
296 struct gfs2_inode *dip = get_v2ip(dir);
297 struct gfs2_sbd *sdp = dip->i_sbd;
298 struct gfs2_inode *ip = get_v2ip(dentry->d_inode);
299 struct gfs2_unlinked *ul;
300 struct gfs2_holder ghs[2];
303 atomic_inc(&sdp->sd_ops_inode);
305 error = gfs2_unlinked_get(sdp, &ul);
309 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
310 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
312 error = gfs2_glock_nq_m(2, ghs);
316 error = gfs2_unlink_ok(dip, &dentry->d_name, ip);
320 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + RES_LEAF +
325 error = gfs2_unlinki(dip, &dentry->d_name, ip,ul);
330 gfs2_glock_dq_m(2, ghs);
333 gfs2_holder_uninit(ghs);
334 gfs2_holder_uninit(ghs + 1);
336 gfs2_unlinked_put(sdp, ul);
342 * gfs2_symlink - Create a symlink
343 * @dir: The directory to create the symlink in
344 * @dentry: The dentry to put the symlink in
345 * @symname: The thing which the link points to
350 static int gfs2_symlink(struct inode *dir, struct dentry *dentry,
353 struct gfs2_inode *dip = get_v2ip(dir), *ip;
354 struct gfs2_sbd *sdp = dip->i_sbd;
355 struct gfs2_holder ghs[2];
357 struct buffer_head *dibh;
361 atomic_inc(&sdp->sd_ops_inode);
363 /* Must be stuffed with a null terminator for gfs2_follow_link() */
364 size = strlen(symname);
365 if (size > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode) - 1)
366 return -ENAMETOOLONG;
368 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
370 error = gfs2_createi(ghs, &dentry->d_name, S_IFLNK | S_IRWXUGO);
372 gfs2_holder_uninit(ghs);
376 ip = get_gl2ip(ghs[1].gh_gl);
378 ip->i_di.di_size = size;
380 error = gfs2_meta_inode_buffer(ip, &dibh);
382 if (!gfs2_assert_withdraw(sdp, !error)) {
383 gfs2_dinode_out(&ip->i_di, dibh->b_data);
384 memcpy(dibh->b_data + sizeof(struct gfs2_dinode), symname,
390 if (dip->i_alloc.al_rgd)
391 gfs2_inplace_release(dip);
392 gfs2_quota_unlock(dip);
395 gfs2_glock_dq_uninit_m(2, ghs);
397 inode = gfs2_ip2v(ip);
403 d_instantiate(dentry, inode);
404 mark_inode_dirty(inode);
410 * gfs2_mkdir - Make a directory
411 * @dir: The parent directory of the new one
412 * @dentry: The dentry of the new directory
413 * @mode: The mode of the new directory
418 static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode)
420 struct gfs2_inode *dip = get_v2ip(dir), *ip;
421 struct gfs2_sbd *sdp = dip->i_sbd;
422 struct gfs2_holder ghs[2];
424 struct buffer_head *dibh;
427 atomic_inc(&sdp->sd_ops_inode);
429 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
431 error = gfs2_createi(ghs, &dentry->d_name, S_IFDIR | mode);
433 gfs2_holder_uninit(ghs);
437 ip = get_gl2ip(ghs[1].gh_gl);
439 ip->i_di.di_nlink = 2;
440 ip->i_di.di_size = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode);
441 ip->i_di.di_flags |= GFS2_DIF_JDATA;
442 ip->i_di.di_payload_format = GFS2_FORMAT_DE;
443 ip->i_di.di_entries = 2;
445 error = gfs2_meta_inode_buffer(ip, &dibh);
447 if (!gfs2_assert_withdraw(sdp, !error)) {
448 struct gfs2_dinode *di = (struct gfs2_dinode *)dibh->b_data;
449 struct gfs2_dirent *dent;
451 gfs2_dirent_alloc(ip, dibh, 1, &dent);
453 dent->de_inum = di->di_num; /* already GFS2 endian */
454 dent->de_hash = gfs2_disk_hash(".", 1);
455 dent->de_hash = cpu_to_be32(dent->de_hash);
456 dent->de_type = DT_DIR;
457 memcpy((char *) (dent + 1), ".", 1);
458 di->di_entries = cpu_to_be32(1);
460 gfs2_dirent_alloc(ip, dibh, 2, &dent);
462 gfs2_inum_out(&dip->i_num, (char *) &dent->de_inum);
463 dent->de_hash = gfs2_disk_hash("..", 2);
464 dent->de_hash = cpu_to_be32(dent->de_hash);
465 dent->de_type = DT_DIR;
466 memcpy((char *) (dent + 1), "..", 2);
468 gfs2_dinode_out(&ip->i_di, (char *)di);
473 error = gfs2_change_nlink(dip, +1);
474 gfs2_assert_withdraw(sdp, !error); /* dip already pinned */
477 if (dip->i_alloc.al_rgd)
478 gfs2_inplace_release(dip);
479 gfs2_quota_unlock(dip);
482 gfs2_glock_dq_uninit_m(2, ghs);
484 inode = gfs2_ip2v(ip);
490 d_instantiate(dentry, inode);
491 mark_inode_dirty(inode);
497 * gfs2_rmdir - Remove a directory
498 * @dir: The parent directory of the directory to be removed
499 * @dentry: The dentry of the directory to remove
501 * Remove a directory. Call gfs2_rmdiri()
506 static int gfs2_rmdir(struct inode *dir, struct dentry *dentry)
508 struct gfs2_inode *dip = get_v2ip(dir);
509 struct gfs2_sbd *sdp = dip->i_sbd;
510 struct gfs2_inode *ip = get_v2ip(dentry->d_inode);
511 struct gfs2_unlinked *ul;
512 struct gfs2_holder ghs[2];
515 atomic_inc(&sdp->sd_ops_inode);
517 error = gfs2_unlinked_get(sdp, &ul);
521 gfs2_holder_init(dip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
522 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
524 error = gfs2_glock_nq_m(2, ghs);
528 error = gfs2_unlink_ok(dip, &dentry->d_name, ip);
532 if (ip->i_di.di_entries < 2) {
533 if (gfs2_consist_inode(ip))
534 gfs2_dinode_print(&ip->i_di);
538 if (ip->i_di.di_entries > 2) {
543 error = gfs2_trans_begin(sdp, 2 * RES_DINODE + 3 * RES_LEAF +
548 error = gfs2_rmdiri(dip, &dentry->d_name, ip, ul);
553 gfs2_glock_dq_m(2, ghs);
556 gfs2_holder_uninit(ghs);
557 gfs2_holder_uninit(ghs + 1);
559 gfs2_unlinked_put(sdp, ul);
565 * gfs2_mknod - Make a special file
566 * @dir: The directory in which the special file will reside
567 * @dentry: The dentry of the special file
568 * @mode: The mode of the special file
569 * @rdev: The device specification of the special file
573 static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode,
576 struct gfs2_inode *dip = get_v2ip(dir), *ip;
577 struct gfs2_sbd *sdp = dip->i_sbd;
578 struct gfs2_holder ghs[2];
580 struct buffer_head *dibh;
581 uint32_t major = 0, minor = 0;
584 atomic_inc(&sdp->sd_ops_inode);
586 switch (mode & S_IFMT) {
599 gfs2_holder_init(dip->i_gl, 0, 0, ghs);
601 error = gfs2_createi(ghs, &dentry->d_name, mode);
603 gfs2_holder_uninit(ghs);
607 ip = get_gl2ip(ghs[1].gh_gl);
609 ip->i_di.di_major = major;
610 ip->i_di.di_minor = minor;
612 error = gfs2_meta_inode_buffer(ip, &dibh);
614 if (!gfs2_assert_withdraw(sdp, !error)) {
615 gfs2_dinode_out(&ip->i_di, dibh->b_data);
620 if (dip->i_alloc.al_rgd)
621 gfs2_inplace_release(dip);
622 gfs2_quota_unlock(dip);
625 gfs2_glock_dq_uninit_m(2, ghs);
627 inode = gfs2_ip2v(ip);
633 d_instantiate(dentry, inode);
634 mark_inode_dirty(inode);
640 * gfs2_rename - Rename a file
641 * @odir: Parent directory of old file name
642 * @odentry: The old dentry of the file
643 * @ndir: Parent directory of new file name
644 * @ndentry: The new dentry of the file
649 static int gfs2_rename(struct inode *odir, struct dentry *odentry,
650 struct inode *ndir, struct dentry *ndentry)
652 struct gfs2_inode *odip = get_v2ip(odir);
653 struct gfs2_inode *ndip = get_v2ip(ndir);
654 struct gfs2_inode *ip = get_v2ip(odentry->d_inode);
655 struct gfs2_inode *nip = NULL;
656 struct gfs2_sbd *sdp = odip->i_sbd;
657 struct gfs2_unlinked *ul;
658 struct gfs2_holder ghs[4], r_gh;
665 atomic_inc(&sdp->sd_ops_inode);
667 if (ndentry->d_inode) {
668 nip = get_v2ip(ndentry->d_inode);
673 error = gfs2_unlinked_get(sdp, &ul);
677 /* Make sure we aren't trying to move a dirctory into it's subdir */
679 if (S_ISDIR(ip->i_di.di_mode) && odip != ndip) {
682 error = gfs2_glock_nq_init(sdp->sd_rename_gl,
688 error = gfs2_ok_to_move(ip, ndip);
693 gfs2_holder_init(odip->i_gl, LM_ST_EXCLUSIVE, 0, ghs);
694 gfs2_holder_init(ndip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 1);
695 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + 2);
699 gfs2_holder_init(nip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh++);
701 error = gfs2_glock_nq_m(num_gh, ghs);
705 /* Check out the old directory */
707 error = gfs2_unlink_ok(odip, &odentry->d_name, ip);
711 /* Check out the new directory */
714 error = gfs2_unlink_ok(ndip, &ndentry->d_name, nip);
718 if (S_ISDIR(nip->i_di.di_mode)) {
719 if (nip->i_di.di_entries < 2) {
720 if (gfs2_consist_inode(nip))
721 gfs2_dinode_print(&nip->i_di);
725 if (nip->i_di.di_entries > 2) {
731 error = gfs2_repermission(ndir, MAY_WRITE | MAY_EXEC, NULL);
735 error = gfs2_dir_search(ndip, &ndentry->d_name, NULL, NULL);
747 if (!ndip->i_di.di_nlink) {
751 if (ndip->i_di.di_entries == (uint32_t)-1) {
755 if (S_ISDIR(ip->i_di.di_mode) &&
756 ndip->i_di.di_nlink == (uint32_t)-1) {
763 /* Check out the dir to be renamed */
766 error = gfs2_repermission(odentry->d_inode, MAY_WRITE, NULL);
771 error = gfs2_diradd_alloc_required(ndip, &ndentry->d_name,
776 if (alloc_required) {
777 struct gfs2_alloc *al = gfs2_alloc_get(ndip);
779 error = gfs2_quota_lock(ndip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
783 error = gfs2_quota_check(ndip, ndip->i_di.di_uid,
788 al->al_requested = sdp->sd_max_dirres;
790 error = gfs2_inplace_reserve(ndip);
794 error = gfs2_trans_begin(sdp,
796 al->al_rgd->rd_ri.ri_length +
797 4 * RES_DINODE + 4 * RES_LEAF +
798 RES_UNLINKED + RES_STATFS +
803 error = gfs2_trans_begin(sdp, 4 * RES_DINODE +
810 /* Remove the target file, if it exists */
813 if (S_ISDIR(nip->i_di.di_mode))
814 error = gfs2_rmdiri(ndip, &ndentry->d_name, nip, ul);
816 error = gfs2_unlinki(ndip, &ndentry->d_name, nip, ul);
826 error = gfs2_change_nlink(ndip, +1);
829 error = gfs2_change_nlink(odip, -1);
833 error = gfs2_dir_mvino(ip, &name, &ndip->i_num, DT_DIR);
837 struct buffer_head *dibh;
838 error = gfs2_meta_inode_buffer(ip, &dibh);
841 ip->i_di.di_ctime = get_seconds();
842 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
843 gfs2_dinode_out(&ip->i_di, dibh->b_data);
847 error = gfs2_dir_del(odip, &odentry->d_name);
851 error = gfs2_dir_add(ndip, &ndentry->d_name, &ip->i_num,
852 IF2DT(ip->i_di.di_mode));
861 gfs2_inplace_release(ndip);
865 gfs2_quota_unlock(ndip);
869 gfs2_alloc_put(ndip);
872 gfs2_glock_dq_m(num_gh, ghs);
875 for (x = 0; x < num_gh; x++)
876 gfs2_holder_uninit(ghs + x);
880 gfs2_glock_dq_uninit(&r_gh);
883 gfs2_unlinked_put(sdp, ul);
889 * gfs2_readlink - Read the value of a symlink
890 * @dentry: the symlink
891 * @buf: the buffer to read the symlink data into
892 * @size: the size of the buffer
897 static int gfs2_readlink(struct dentry *dentry, char __user *user_buf,
900 struct gfs2_inode *ip = get_v2ip(dentry->d_inode);
901 char array[GFS2_FAST_NAME_SIZE], *buf = array;
902 unsigned int len = GFS2_FAST_NAME_SIZE;
905 atomic_inc(&ip->i_sbd->sd_ops_inode);
907 error = gfs2_readlinki(ip, &buf, &len);
911 if (user_size > len - 1)
914 if (copy_to_user(user_buf, buf, user_size))
926 * gfs2_follow_link - Follow a symbolic link
927 * @dentry: The dentry of the link
928 * @nd: Data that we pass to vfs_follow_link()
930 * This can handle symlinks of any size. It is optimised for symlinks
931 * under GFS2_FAST_NAME_SIZE.
933 * Returns: 0 on success or error code
936 static void *gfs2_follow_link(struct dentry *dentry, struct nameidata *nd)
938 struct gfs2_inode *ip = get_v2ip(dentry->d_inode);
939 char array[GFS2_FAST_NAME_SIZE], *buf = array;
940 unsigned int len = GFS2_FAST_NAME_SIZE;
943 atomic_inc(&ip->i_sbd->sd_ops_inode);
945 error = gfs2_readlinki(ip, &buf, &len);
947 error = vfs_follow_link(nd, buf);
952 return ERR_PTR(error);
959 * @nd: passed from Linux VFS, ignored by us
964 static int gfs2_permission(struct inode *inode, int mask, struct nameidata *nd)
966 struct gfs2_inode *ip = get_v2ip(inode);
967 struct gfs2_holder i_gh;
970 atomic_inc(&ip->i_sbd->sd_ops_inode);
972 if (ip->i_vn == ip->i_gl->gl_vn)
973 return generic_permission(inode, mask, gfs2_check_acl);
975 error = gfs2_glock_nq_init(ip->i_gl,
976 LM_ST_SHARED, LM_FLAG_ANY,
979 error = generic_permission(inode, mask, gfs2_check_acl_locked);
980 gfs2_glock_dq_uninit(&i_gh);
986 static int setattr_size(struct inode *inode, struct iattr *attr)
988 struct gfs2_inode *ip = get_v2ip(inode);
991 if (attr->ia_size != ip->i_di.di_size) {
992 error = vmtruncate(inode, attr->ia_size);
997 error = gfs2_truncatei(ip, attr->ia_size, gfs2_truncator_page);
1004 static int setattr_chown(struct inode *inode, struct iattr *attr)
1006 struct gfs2_inode *ip = get_v2ip(inode);
1007 struct gfs2_sbd *sdp = ip->i_sbd;
1008 struct buffer_head *dibh;
1009 uint32_t ouid, ogid, nuid, ngid;
1012 ouid = ip->i_di.di_uid;
1013 ogid = ip->i_di.di_gid;
1014 nuid = attr->ia_uid;
1015 ngid = attr->ia_gid;
1017 if (!(attr->ia_valid & ATTR_UID) || ouid == nuid)
1018 ouid = nuid = NO_QUOTA_CHANGE;
1019 if (!(attr->ia_valid & ATTR_GID) || ogid == ngid)
1020 ogid = ngid = NO_QUOTA_CHANGE;
1024 error = gfs2_quota_lock(ip, nuid, ngid);
1028 if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) {
1029 error = gfs2_quota_check(ip, nuid, ngid);
1034 error = gfs2_trans_begin(sdp, RES_DINODE + 2 * RES_QUOTA, 0);
1038 error = gfs2_meta_inode_buffer(ip, &dibh);
1042 error = inode_setattr(inode, attr);
1043 gfs2_assert_warn(sdp, !error);
1044 gfs2_inode_attr_out(ip);
1046 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
1047 gfs2_dinode_out(&ip->i_di, dibh->b_data);
1050 if (ouid != NO_QUOTA_CHANGE || ogid != NO_QUOTA_CHANGE) {
1051 gfs2_quota_change(ip, -ip->i_di.di_blocks,
1053 gfs2_quota_change(ip, ip->i_di.di_blocks,
1058 gfs2_trans_end(sdp);
1061 gfs2_quota_unlock(ip);
1070 * gfs2_setattr - Change attributes on an inode
1071 * @dentry: The dentry which is changing
1072 * @attr: The structure describing the change
1074 * The VFS layer wants to change one or more of an inodes attributes. Write
1075 * that change out to disk.
1080 static int gfs2_setattr(struct dentry *dentry, struct iattr *attr)
1082 struct inode *inode = dentry->d_inode;
1083 struct gfs2_inode *ip = get_v2ip(inode);
1084 struct gfs2_holder i_gh;
1087 atomic_inc(&ip->i_sbd->sd_ops_inode);
1089 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh);
1094 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1097 error = inode_change_ok(inode, attr);
1101 if (attr->ia_valid & ATTR_SIZE)
1102 error = setattr_size(inode, attr);
1103 else if (attr->ia_valid & (ATTR_UID | ATTR_GID))
1104 error = setattr_chown(inode, attr);
1105 else if ((attr->ia_valid & ATTR_MODE) && IS_POSIXACL(inode))
1106 error = gfs2_acl_chmod(ip, attr);
1108 error = gfs2_setattr_simple(ip, attr);
1111 gfs2_glock_dq_uninit(&i_gh);
1114 mark_inode_dirty(inode);
1120 * gfs2_getattr - Read out an inode's attributes
1122 * @dentry: The dentry to stat
1123 * @stat: The inode's stats
1128 static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry,
1131 struct inode *inode = dentry->d_inode;
1132 struct gfs2_inode *ip = get_v2ip(inode);
1133 struct gfs2_holder gh;
1136 atomic_inc(&ip->i_sbd->sd_ops_inode);
1138 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
1140 generic_fillattr(inode, stat);
1141 gfs2_glock_dq_uninit(&gh);
1147 static int gfs2_setxattr(struct dentry *dentry, const char *name,
1148 const void *data, size_t size, int flags)
1150 struct gfs2_inode *ip = get_v2ip(dentry->d_inode);
1151 struct gfs2_ea_request er;
1153 atomic_inc(&ip->i_sbd->sd_ops_inode);
1155 memset(&er, 0, sizeof(struct gfs2_ea_request));
1156 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1157 if (er.er_type == GFS2_EATYPE_UNUSED)
1159 er.er_data = (char *)data;
1160 er.er_name_len = strlen(er.er_name);
1161 er.er_data_len = size;
1162 er.er_flags = flags;
1164 gfs2_assert_warn(ip->i_sbd, !(er.er_flags & GFS2_ERF_MODE));
1166 return gfs2_ea_set(ip, &er);
1169 static ssize_t gfs2_getxattr(struct dentry *dentry, const char *name,
1170 void *data, size_t size)
1172 struct gfs2_ea_request er;
1174 atomic_inc(&get_v2sdp(dentry->d_inode->i_sb)->sd_ops_inode);
1176 memset(&er, 0, sizeof(struct gfs2_ea_request));
1177 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1178 if (er.er_type == GFS2_EATYPE_UNUSED)
1181 er.er_name_len = strlen(er.er_name);
1182 er.er_data_len = size;
1184 return gfs2_ea_get(get_v2ip(dentry->d_inode), &er);
1187 static ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size)
1189 struct gfs2_ea_request er;
1191 atomic_inc(&get_v2sdp(dentry->d_inode->i_sb)->sd_ops_inode);
1193 memset(&er, 0, sizeof(struct gfs2_ea_request));
1194 er.er_data = (size) ? buffer : NULL;
1195 er.er_data_len = size;
1197 return gfs2_ea_list(get_v2ip(dentry->d_inode), &er);
1200 static int gfs2_removexattr(struct dentry *dentry, const char *name)
1202 struct gfs2_ea_request er;
1204 atomic_inc(&get_v2sdp(dentry->d_inode->i_sb)->sd_ops_inode);
1206 memset(&er, 0, sizeof(struct gfs2_ea_request));
1207 er.er_type = gfs2_ea_name2type(name, &er.er_name);
1208 if (er.er_type == GFS2_EATYPE_UNUSED)
1210 er.er_name_len = strlen(er.er_name);
1212 return gfs2_ea_remove(get_v2ip(dentry->d_inode), &er);
1215 struct inode_operations gfs2_file_iops = {
1216 .permission = gfs2_permission,
1217 .setattr = gfs2_setattr,
1218 .getattr = gfs2_getattr,
1219 .setxattr = gfs2_setxattr,
1220 .getxattr = gfs2_getxattr,
1221 .listxattr = gfs2_listxattr,
1222 .removexattr = gfs2_removexattr,
1225 struct inode_operations gfs2_dev_iops = {
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,
1235 struct inode_operations gfs2_dir_iops = {
1236 .create = gfs2_create,
1237 .lookup = gfs2_lookup,
1239 .unlink = gfs2_unlink,
1240 .symlink = gfs2_symlink,
1241 .mkdir = gfs2_mkdir,
1242 .rmdir = gfs2_rmdir,
1243 .mknod = gfs2_mknod,
1244 .rename = gfs2_rename,
1245 .permission = gfs2_permission,
1246 .setattr = gfs2_setattr,
1247 .getattr = gfs2_getattr,
1248 .setxattr = gfs2_setxattr,
1249 .getxattr = gfs2_getxattr,
1250 .listxattr = gfs2_listxattr,
1251 .removexattr = gfs2_removexattr,
1254 struct inode_operations gfs2_symlink_iops = {
1255 .readlink = gfs2_readlink,
1256 .follow_link = gfs2_follow_link,
1257 .permission = gfs2_permission,
1258 .setattr = gfs2_setattr,
1259 .getattr = gfs2_getattr,
1260 .setxattr = gfs2_setxattr,
1261 .getxattr = gfs2_getxattr,
1262 .listxattr = gfs2_listxattr,
1263 .removexattr = gfs2_removexattr,