10 #include <linux/slab.h>
16 #include <linux/xattr.h>
22 #include <asm/uaccess.h>
46 static int iget_test(
struct inode *
inode,
void *opaque)
62 static int iget_set(
struct inode *
inode,
void *opaque)
76 unsigned long hash = (
unsigned long)no_addr;
82 return ilookup5(sb, hash, iget_test, &data);
89 unsigned long hash = (
unsigned long)no_addr;
94 return iget5_locked(sb, hash, iget_test, iget_set, &data);
105 static void gfs2_set_iop(
struct inode *inode)
107 struct gfs2_sbd *sdp = GFS2_SB(inode);
112 if (gfs2_localflocks(sdp))
118 if (gfs2_localflocks(sdp))
141 u64 no_addr,
u64 no_formal_ino,
int non_block)
148 inode = gfs2_iget(sb, no_addr, non_block);
155 struct gfs2_sbd *sdp = GFS2_SB(inode);
202 return ERR_PTR(error);
206 u64 *no_formal_ino,
unsigned int blktype)
210 struct inode *inode =
NULL;
217 return ERR_PTR(error);
230 if (GFS2_I(inode)->i_no_formal_ino != *no_formal_ino)
242 return error ? ERR_PTR(error) :
inode;
253 gfs2_str2qstr(&qstr, name);
289 struct inode *inode =
NULL;
295 if ((name->len == 1 &&
memcmp(name->
name,
".", 1) == 0) ||
296 (name->len == 2 &&
memcmp(name->
name,
"..", 2) == 0 &&
297 dir == sb->
s_root->d_inode)) {
302 if (gfs2_glock_is_locked_by_me(dip->
i_gl) ==
NULL) {
305 return ERR_PTR(error);
317 error = PTR_ERR(inode);
323 return inode ? inode : ERR_PTR(error);
368 unsigned int *
uid,
unsigned int *
gid)
370 if (GFS2_SB(&dip->
i_inode)->sd_args.ar_suiddir &&
412 static void gfs2_init_dir(
struct buffer_head *dibh,
419 dent->de_inum = di->
di_num;
424 gfs2_inum_out(parent, dent);
447 unsigned int uid,
unsigned int gid,
448 const u64 *generation,
dev_t dev,
const char *symname,
449 unsigned size,
struct buffer_head **bhp)
453 struct buffer_head *dibh;
459 gfs2_buffer_clear_tail(dibh,
sizeof(
struct gfs2_dinode));
502 gfs2_init_dir(dibh, dip);
509 set_buffer_uptodate(dibh);
516 const u64 *generation,
dev_t dev,
const char *symname,
517 unsigned int size,
struct buffer_head **bhp)
523 munge_mode_uid_gid(dip, &mode, &uid, &gid);
540 init_dinode(dip, gl, inum, mode, uid, gid, generation, dev, symname, size, bhp);
549 static int link_dinode(
struct gfs2_inode *dip,
const struct qstr *name,
554 struct buffer_head *dibh;
566 if (alloc_required < 0)
567 goto fail_quota_locks;
568 if (alloc_required) {
571 goto fail_quota_locks;
575 goto fail_quota_locks;
578 dip->
i_rgd->rd_length +
586 goto fail_quota_locks;
593 error = gfs2_meta_inode_buffer(ip, &dibh);
616 static int gfs2_initxattrs(
struct inode *inode,
const struct xattr *xattr_array,
622 for (xattr = xattr_array; xattr->
name !=
NULL; xattr++) {
636 &gfs2_initxattrs,
NULL);
651 static int gfs2_create_inode(
struct inode *dir,
struct dentry *
dentry,
653 unsigned int size,
int excl)
657 struct inode *inode =
NULL;
663 struct buffer_head *bh =
NULL;
681 error = create_ok(dip, name, mode);
686 return IS_ERR(inode) ? PTR_ERR(inode) : 0;
691 error = alloc_dinode(dip, &inum.
no_addr, &generation);
701 error = make_dinode(dip, ghs[1].gh_gl, mode, &inum, &generation, dev, symname, size, &bh);
723 error = gfs2_security_init(dip, ip, name);
727 error = link_dinode(dip, name, ip);
737 mark_inode_dirty(inode);
746 if (inode && !IS_ERR(inode)) {
766 static int gfs2_create(
struct inode *dir,
struct dentry *dentry,
769 return gfs2_create_inode(dir, dentry,
S_IFREG | mode, 0,
NULL, 0, excl);
783 static struct dentry *gfs2_lookup(
struct inode *dir,
struct dentry *dentry,
787 if (inode && !IS_ERR(inode)) {
794 return ERR_PTR(error);
813 static int gfs2_link(
struct dentry *old_dentry,
struct inode *dir,
814 struct dentry *dentry)
817 struct gfs2_sbd *sdp = GFS2_SB(dir);
818 struct inode *inode = old_dentry->
d_inode;
821 struct buffer_head *dibh;
882 if (alloc_required) {
883 error = gfs2_quota_lock_check(dip);
903 error = gfs2_meta_inode_buffer(ip, &dibh);
916 mark_inode_dirty(inode);
949 static int gfs2_unlink_ok(
struct gfs2_inode *dip,
const struct qstr *name,
989 static int gfs2_unlink_inode(
struct gfs2_inode *dip,
990 const struct dentry *dentry,
991 struct buffer_head *bh)
993 struct inode *inode = dentry->
d_inode;
1007 mark_inode_dirty(inode);
1025 static int gfs2_unlink(
struct inode *dir,
struct dentry *dentry)
1028 struct gfs2_sbd *sdp = GFS2_SB(dir);
1029 struct inode *inode = dentry->
d_inode;
1031 struct buffer_head *bh;
1074 error = gfs2_unlink_ok(dip, &dentry->
d_name, ip);
1082 error = gfs2_meta_inode_buffer(ip, &bh);
1086 error = gfs2_unlink_inode(dip, dentry, bh);
1114 static int gfs2_symlink(
struct inode *dir,
struct dentry *dentry,
1115 const char *symname)
1117 struct gfs2_sbd *sdp = GFS2_SB(dir);
1124 return gfs2_create_inode(dir, dentry,
S_IFLNK |
S_IRWXUGO, 0, symname, size, 0);
1136 static int gfs2_mkdir(
struct inode *dir,
struct dentry *dentry,
umode_t mode)
1138 return gfs2_create_inode(dir, dentry,
S_IFDIR | mode, 0,
NULL, 0, 0);
1150 static int gfs2_mknod(
struct inode *dir,
struct dentry *dentry,
umode_t mode,
1153 return gfs2_create_inode(dir, dentry, mode, dev,
NULL, 0, 0);
1169 struct inode *dir = &to->
i_inode;
1177 if (dir == &this->i_inode) {
1181 if (dir == sb->
s_root->d_inode) {
1188 error = PTR_ERR(tmp);
1211 static int gfs2_rename(
struct inode *odir,
struct dentry *odentry,
1212 struct inode *ndir,
struct dentry *ndentry)
1218 struct gfs2_sbd *sdp = GFS2_SB(odir);
1221 unsigned int num_gh;
1223 int alloc_required = 0;
1228 nip = GFS2_I(ndentry->
d_inode);
1250 error = gfs2_ok_to_move(ip, ndip);
1277 for (x = 0; x < num_gh; x++) {
1289 error = gfs2_unlink_ok(odip, &odentry->
d_name, ip);
1296 error = gfs2_unlink_ok(ndip, &ndentry->
d_name, nip);
1300 if (nip->
i_inode.i_nlink == 0) {
1359 error = alloc_required;
1363 if (alloc_required) {
1364 error = gfs2_quota_lock_check(ndip);
1388 struct buffer_head *bh;
1389 error = gfs2_meta_inode_buffer(nip, &bh);
1392 error = gfs2_unlink_inode(ndip, ndentry, bh);
1401 struct buffer_head *dibh;
1402 error = gfs2_meta_inode_buffer(ip, &dibh);
1449 static void *gfs2_follow_link(
struct dentry *dentry,
struct nameidata *nd)
1453 struct buffer_head *dibh;
1462 nd_set_link(nd, ERR_PTR(error));
1466 size = (
unsigned int)i_size_read(&ip->
i_inode);
1469 buf = ERR_PTR(-
EIO);
1473 error = gfs2_meta_inode_buffer(ip, &dibh);
1475 buf = ERR_PTR(error);
1487 nd_set_link(nd, buf);
1491 static void gfs2_put_link(
struct dentry *dentry,
struct nameidata *nd,
void *
p)
1493 char *
s = nd_get_link(nd);
1520 if (gfs2_glock_is_locked_by_me(ip->
i_gl) ==
NULL) {
1539 static int __gfs2_setattr_simple(
struct inode *inode,
struct iattr *
attr)
1542 mark_inode_dirty(inode);
1559 return __gfs2_setattr_simple(inode, attr);
1565 error = __gfs2_setattr_simple(inode, attr);
1570 static int setattr_chown(
struct inode *inode,
struct iattr *
attr)
1573 struct gfs2_sbd *sdp = GFS2_SB(inode);
1574 u32 ouid, ogid, nuid, ngid;
1577 ouid = inode->
i_uid;
1578 ogid = inode->
i_gid;
1606 u64 blocks = gfs2_get_inode_blocks(&ip->
i_inode);
1629 static int gfs2_setattr(
struct dentry *dentry,
struct iattr *attr)
1631 struct inode *inode = dentry->
d_inode;
1655 error = setattr_chown(inode, attr);
1663 mark_inode_dirty(inode);
1683 static int gfs2_getattr(
struct vfsmount *mnt,
struct dentry *dentry,
1686 struct inode *inode = dentry->
d_inode;
1692 if (gfs2_glock_is_locked_by_me(ip->
i_gl) ==
NULL) {
1706 static int gfs2_setxattr(
struct dentry *dentry,
const char *name,
1707 const void *data,
size_t size,
int flags)
1709 struct inode *inode = dentry->
d_inode;
1726 static ssize_t gfs2_getxattr(
struct dentry *dentry,
const char *name,
1727 void *data,
size_t size)
1729 struct inode *inode = dentry->
d_inode;
1744 static int gfs2_removexattr(
struct dentry *dentry,
const char *name)
1746 struct inode *inode = dentry->
d_inode;
1780 if (gfs2_is_stuffed(ip)) {
1782 u64 size = i_size_read(inode);
1787 if (start + len > size)
1807 .setattr = gfs2_setattr,
1808 .getattr = gfs2_getattr,
1809 .setxattr = gfs2_setxattr,
1810 .getxattr = gfs2_getxattr,
1812 .removexattr = gfs2_removexattr,
1813 .fiemap = gfs2_fiemap,
1818 .create = gfs2_create,
1819 .lookup = gfs2_lookup,
1821 .unlink = gfs2_unlink,
1822 .symlink = gfs2_symlink,
1823 .mkdir = gfs2_mkdir,
1824 .rmdir = gfs2_unlink,
1825 .mknod = gfs2_mknod,
1826 .rename = gfs2_rename,
1828 .setattr = gfs2_setattr,
1829 .getattr = gfs2_getattr,
1830 .setxattr = gfs2_setxattr,
1831 .getxattr = gfs2_getxattr,
1833 .removexattr = gfs2_removexattr,
1834 .fiemap = gfs2_fiemap,
1840 .follow_link = gfs2_follow_link,
1841 .put_link = gfs2_put_link,
1843 .setattr = gfs2_setattr,
1844 .getattr = gfs2_getattr,
1845 .setxattr = gfs2_setxattr,
1846 .getxattr = gfs2_getxattr,
1848 .removexattr = gfs2_removexattr,
1849 .fiemap = gfs2_fiemap,