aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/linux-2.6
diff options
context:
space:
mode:
Diffstat (limited to 'fs/xfs/linux-2.6')
-rw-r--r--fs/xfs/linux-2.6/kmem.c6
-rw-r--r--fs/xfs/linux-2.6/kmem.h4
-rw-r--r--fs/xfs/linux-2.6/xfs_aops.c11
-rw-r--r--fs/xfs/linux-2.6/xfs_buf.c14
-rw-r--r--fs/xfs/linux-2.6/xfs_buf.h2
-rw-r--r--fs/xfs/linux-2.6/xfs_export.c2
-rw-r--r--fs/xfs/linux-2.6/xfs_ioctl.c376
-rw-r--r--fs/xfs/linux-2.6/xfs_iops.c345
-rw-r--r--fs/xfs/linux-2.6/xfs_iops.h2
-rw-r--r--fs/xfs/linux-2.6/xfs_linux.h8
-rw-r--r--fs/xfs/linux-2.6/xfs_stats.c15
-rw-r--r--fs/xfs/linux-2.6/xfs_stats.h12
-rw-r--r--fs/xfs/linux-2.6/xfs_super.c938
-rw-r--r--fs/xfs/linux-2.6/xfs_super.h4
-rw-r--r--fs/xfs/linux-2.6/xfs_sysctl.c8
-rw-r--r--fs/xfs/linux-2.6/xfs_sysctl.h4
-rw-r--r--fs/xfs/linux-2.6/xfs_vnode.c50
-rw-r--r--fs/xfs/linux-2.6/xfs_vnode.h89
-rw-r--r--fs/xfs/linux-2.6/xfs_xattr.c330
19 files changed, 1682 insertions, 538 deletions
diff --git a/fs/xfs/linux-2.6/kmem.c b/fs/xfs/linux-2.6/kmem.c
index 9b1bb17a0501..1cd3b55ee3d2 100644
--- a/fs/xfs/linux-2.6/kmem.c
+++ b/fs/xfs/linux-2.6/kmem.c
@@ -90,7 +90,7 @@ kmem_zalloc_greedy(size_t *size, size_t minsize, size_t maxsize,
90} 90}
91 91
92void 92void
93kmem_free(void *ptr, size_t size) 93kmem_free(const void *ptr)
94{ 94{
95 if (!is_vmalloc_addr(ptr)) { 95 if (!is_vmalloc_addr(ptr)) {
96 kfree(ptr); 96 kfree(ptr);
@@ -100,7 +100,7 @@ kmem_free(void *ptr, size_t size)
100} 100}
101 101
102void * 102void *
103kmem_realloc(void *ptr, size_t newsize, size_t oldsize, 103kmem_realloc(const void *ptr, size_t newsize, size_t oldsize,
104 unsigned int __nocast flags) 104 unsigned int __nocast flags)
105{ 105{
106 void *new; 106 void *new;
@@ -110,7 +110,7 @@ kmem_realloc(void *ptr, size_t newsize, size_t oldsize,
110 if (new) 110 if (new)
111 memcpy(new, ptr, 111 memcpy(new, ptr,
112 ((oldsize < newsize) ? oldsize : newsize)); 112 ((oldsize < newsize) ? oldsize : newsize));
113 kmem_free(ptr, oldsize); 113 kmem_free(ptr);
114 } 114 }
115 return new; 115 return new;
116} 116}
diff --git a/fs/xfs/linux-2.6/kmem.h b/fs/xfs/linux-2.6/kmem.h
index a20683cf74dd..af6843c7ee4b 100644
--- a/fs/xfs/linux-2.6/kmem.h
+++ b/fs/xfs/linux-2.6/kmem.h
@@ -57,8 +57,8 @@ kmem_flags_convert(unsigned int __nocast flags)
57extern void *kmem_alloc(size_t, unsigned int __nocast); 57extern void *kmem_alloc(size_t, unsigned int __nocast);
58extern void *kmem_zalloc(size_t, unsigned int __nocast); 58extern void *kmem_zalloc(size_t, unsigned int __nocast);
59extern void *kmem_zalloc_greedy(size_t *, size_t, size_t, unsigned int __nocast); 59extern void *kmem_zalloc_greedy(size_t *, size_t, size_t, unsigned int __nocast);
60extern void *kmem_realloc(void *, size_t, size_t, unsigned int __nocast); 60extern void *kmem_realloc(const void *, size_t, size_t, unsigned int __nocast);
61extern void kmem_free(void *, size_t); 61extern void kmem_free(const void *);
62 62
63/* 63/*
64 * Zone interfaces 64 * Zone interfaces
diff --git a/fs/xfs/linux-2.6/xfs_aops.c b/fs/xfs/linux-2.6/xfs_aops.c
index a55c3b26d840..fa47e43b8b41 100644
--- a/fs/xfs/linux-2.6/xfs_aops.c
+++ b/fs/xfs/linux-2.6/xfs_aops.c
@@ -409,7 +409,6 @@ xfs_start_buffer_writeback(
409STATIC void 409STATIC void
410xfs_start_page_writeback( 410xfs_start_page_writeback(
411 struct page *page, 411 struct page *page,
412 struct writeback_control *wbc,
413 int clear_dirty, 412 int clear_dirty,
414 int buffers) 413 int buffers)
415{ 414{
@@ -676,7 +675,7 @@ xfs_probe_cluster(
676 } else 675 } else
677 pg_offset = PAGE_CACHE_SIZE; 676 pg_offset = PAGE_CACHE_SIZE;
678 677
679 if (page->index == tindex && !TestSetPageLocked(page)) { 678 if (page->index == tindex && trylock_page(page)) {
680 pg_len = xfs_probe_page(page, pg_offset, mapped); 679 pg_len = xfs_probe_page(page, pg_offset, mapped);
681 unlock_page(page); 680 unlock_page(page);
682 } 681 }
@@ -760,7 +759,7 @@ xfs_convert_page(
760 759
761 if (page->index != tindex) 760 if (page->index != tindex)
762 goto fail; 761 goto fail;
763 if (TestSetPageLocked(page)) 762 if (!trylock_page(page))
764 goto fail; 763 goto fail;
765 if (PageWriteback(page)) 764 if (PageWriteback(page))
766 goto fail_unlock_page; 765 goto fail_unlock_page;
@@ -858,7 +857,7 @@ xfs_convert_page(
858 done = 1; 857 done = 1;
859 } 858 }
860 } 859 }
861 xfs_start_page_writeback(page, wbc, !page_dirty, count); 860 xfs_start_page_writeback(page, !page_dirty, count);
862 } 861 }
863 862
864 return done; 863 return done;
@@ -1105,7 +1104,7 @@ xfs_page_state_convert(
1105 * that we are writing into for the first time. 1104 * that we are writing into for the first time.
1106 */ 1105 */
1107 type = IOMAP_NEW; 1106 type = IOMAP_NEW;
1108 if (!test_and_set_bit(BH_Lock, &bh->b_state)) { 1107 if (trylock_buffer(bh)) {
1109 ASSERT(buffer_mapped(bh)); 1108 ASSERT(buffer_mapped(bh));
1110 if (iomap_valid) 1109 if (iomap_valid)
1111 all_bh = 1; 1110 all_bh = 1;
@@ -1130,7 +1129,7 @@ xfs_page_state_convert(
1130 SetPageUptodate(page); 1129 SetPageUptodate(page);
1131 1130
1132 if (startio) 1131 if (startio)
1133 xfs_start_page_writeback(page, wbc, 1, count); 1132 xfs_start_page_writeback(page, 1, count);
1134 1133
1135 if (ioend && iomap_valid) { 1134 if (ioend && iomap_valid) {
1136 offset = (iomap.iomap_offset + iomap.iomap_bsize - 1) >> 1135 offset = (iomap.iomap_offset + iomap.iomap_bsize - 1) >>
diff --git a/fs/xfs/linux-2.6/xfs_buf.c b/fs/xfs/linux-2.6/xfs_buf.c
index 98e0e86093b4..9cc8f0213095 100644
--- a/fs/xfs/linux-2.6/xfs_buf.c
+++ b/fs/xfs/linux-2.6/xfs_buf.c
@@ -310,8 +310,7 @@ _xfs_buf_free_pages(
310 xfs_buf_t *bp) 310 xfs_buf_t *bp)
311{ 311{
312 if (bp->b_pages != bp->b_page_array) { 312 if (bp->b_pages != bp->b_page_array) {
313 kmem_free(bp->b_pages, 313 kmem_free(bp->b_pages);
314 bp->b_page_count * sizeof(struct page *));
315 } 314 }
316} 315}
317 316
@@ -1398,7 +1397,7 @@ STATIC void
1398xfs_free_bufhash( 1397xfs_free_bufhash(
1399 xfs_buftarg_t *btp) 1398 xfs_buftarg_t *btp)
1400{ 1399{
1401 kmem_free(btp->bt_hash, (1<<btp->bt_hashshift) * sizeof(xfs_bufhash_t)); 1400 kmem_free(btp->bt_hash);
1402 btp->bt_hash = NULL; 1401 btp->bt_hash = NULL;
1403} 1402}
1404 1403
@@ -1428,13 +1427,10 @@ xfs_unregister_buftarg(
1428 1427
1429void 1428void
1430xfs_free_buftarg( 1429xfs_free_buftarg(
1431 xfs_buftarg_t *btp, 1430 xfs_buftarg_t *btp)
1432 int external)
1433{ 1431{
1434 xfs_flush_buftarg(btp, 1); 1432 xfs_flush_buftarg(btp, 1);
1435 xfs_blkdev_issue_flush(btp); 1433 xfs_blkdev_issue_flush(btp);
1436 if (external)
1437 xfs_blkdev_put(btp->bt_bdev);
1438 xfs_free_bufhash(btp); 1434 xfs_free_bufhash(btp);
1439 iput(btp->bt_mapping->host); 1435 iput(btp->bt_mapping->host);
1440 1436
@@ -1444,7 +1440,7 @@ xfs_free_buftarg(
1444 xfs_unregister_buftarg(btp); 1440 xfs_unregister_buftarg(btp);
1445 kthread_stop(btp->bt_task); 1441 kthread_stop(btp->bt_task);
1446 1442
1447 kmem_free(btp, sizeof(*btp)); 1443 kmem_free(btp);
1448} 1444}
1449 1445
1450STATIC int 1446STATIC int
@@ -1575,7 +1571,7 @@ xfs_alloc_buftarg(
1575 return btp; 1571 return btp;
1576 1572
1577error: 1573error:
1578 kmem_free(btp, sizeof(*btp)); 1574 kmem_free(btp);
1579 return NULL; 1575 return NULL;
1580} 1576}
1581 1577
diff --git a/fs/xfs/linux-2.6/xfs_buf.h b/fs/xfs/linux-2.6/xfs_buf.h
index f948ec7ba9a4..29d1d4adc078 100644
--- a/fs/xfs/linux-2.6/xfs_buf.h
+++ b/fs/xfs/linux-2.6/xfs_buf.h
@@ -429,7 +429,7 @@ static inline void xfs_bdwrite(void *mp, xfs_buf_t *bp)
429 * Handling of buftargs. 429 * Handling of buftargs.
430 */ 430 */
431extern xfs_buftarg_t *xfs_alloc_buftarg(struct block_device *, int); 431extern xfs_buftarg_t *xfs_alloc_buftarg(struct block_device *, int);
432extern void xfs_free_buftarg(xfs_buftarg_t *, int); 432extern void xfs_free_buftarg(xfs_buftarg_t *);
433extern void xfs_wait_buftarg(xfs_buftarg_t *); 433extern void xfs_wait_buftarg(xfs_buftarg_t *);
434extern int xfs_setsize_buftarg(xfs_buftarg_t *, unsigned int, unsigned int); 434extern int xfs_setsize_buftarg(xfs_buftarg_t *, unsigned int, unsigned int);
435extern int xfs_flush_buftarg(xfs_buftarg_t *, int); 435extern int xfs_flush_buftarg(xfs_buftarg_t *, int);
diff --git a/fs/xfs/linux-2.6/xfs_export.c b/fs/xfs/linux-2.6/xfs_export.c
index c672b3238b14..987fe84f7b13 100644
--- a/fs/xfs/linux-2.6/xfs_export.c
+++ b/fs/xfs/linux-2.6/xfs_export.c
@@ -215,7 +215,7 @@ xfs_fs_get_parent(
215 struct xfs_inode *cip; 215 struct xfs_inode *cip;
216 struct dentry *parent; 216 struct dentry *parent;
217 217
218 error = xfs_lookup(XFS_I(child->d_inode), &xfs_name_dotdot, &cip); 218 error = xfs_lookup(XFS_I(child->d_inode), &xfs_name_dotdot, &cip, NULL);
219 if (unlikely(error)) 219 if (unlikely(error))
220 return ERR_PTR(-error); 220 return ERR_PTR(-error);
221 221
diff --git a/fs/xfs/linux-2.6/xfs_ioctl.c b/fs/xfs/linux-2.6/xfs_ioctl.c
index 01939ba2d8de..acb978d9d085 100644
--- a/fs/xfs/linux-2.6/xfs_ioctl.c
+++ b/fs/xfs/linux-2.6/xfs_ioctl.c
@@ -48,6 +48,8 @@
48#include "xfs_dfrag.h" 48#include "xfs_dfrag.h"
49#include "xfs_fsops.h" 49#include "xfs_fsops.h"
50#include "xfs_vnodeops.h" 50#include "xfs_vnodeops.h"
51#include "xfs_quota.h"
52#include "xfs_inode_item.h"
51 53
52#include <linux/capability.h> 54#include <linux/capability.h>
53#include <linux/dcache.h> 55#include <linux/dcache.h>
@@ -468,6 +470,12 @@ xfs_attrlist_by_handle(
468 if (al_hreq.buflen > XATTR_LIST_MAX) 470 if (al_hreq.buflen > XATTR_LIST_MAX)
469 return -XFS_ERROR(EINVAL); 471 return -XFS_ERROR(EINVAL);
470 472
473 /*
474 * Reject flags, only allow namespaces.
475 */
476 if (al_hreq.flags & ~(ATTR_ROOT | ATTR_SECURE))
477 return -XFS_ERROR(EINVAL);
478
471 error = xfs_vget_fsop_handlereq(mp, parinode, &al_hreq.hreq, &inode); 479 error = xfs_vget_fsop_handlereq(mp, parinode, &al_hreq.hreq, &inode);
472 if (error) 480 if (error)
473 goto out; 481 goto out;
@@ -587,7 +595,7 @@ xfs_attrmulti_by_handle(
587 goto out; 595 goto out;
588 596
589 error = E2BIG; 597 error = E2BIG;
590 size = am_hreq.opcount * sizeof(attr_multiop_t); 598 size = am_hreq.opcount * sizeof(xfs_attr_multiop_t);
591 if (!size || size > 16 * PAGE_SIZE) 599 if (!size || size > 16 * PAGE_SIZE)
592 goto out_vn_rele; 600 goto out_vn_rele;
593 601
@@ -680,9 +688,9 @@ xfs_ioc_space(
680 return -XFS_ERROR(EFAULT); 688 return -XFS_ERROR(EFAULT);
681 689
682 if (filp->f_flags & (O_NDELAY|O_NONBLOCK)) 690 if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
683 attr_flags |= ATTR_NONBLOCK; 691 attr_flags |= XFS_ATTR_NONBLOCK;
684 if (ioflags & IO_INVIS) 692 if (ioflags & IO_INVIS)
685 attr_flags |= ATTR_DMI; 693 attr_flags |= XFS_ATTR_DMI;
686 694
687 error = xfs_change_file_space(ip, cmd, &bf, filp->f_pos, 695 error = xfs_change_file_space(ip, cmd, &bf, filp->f_pos,
688 NULL, attr_flags); 696 NULL, attr_flags);
@@ -873,6 +881,322 @@ xfs_ioc_fsgetxattr(
873 return 0; 881 return 0;
874} 882}
875 883
884STATIC void
885xfs_set_diflags(
886 struct xfs_inode *ip,
887 unsigned int xflags)
888{
889 unsigned int di_flags;
890
891 /* can't set PREALLOC this way, just preserve it */
892 di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
893 if (xflags & XFS_XFLAG_IMMUTABLE)
894 di_flags |= XFS_DIFLAG_IMMUTABLE;
895 if (xflags & XFS_XFLAG_APPEND)
896 di_flags |= XFS_DIFLAG_APPEND;
897 if (xflags & XFS_XFLAG_SYNC)
898 di_flags |= XFS_DIFLAG_SYNC;
899 if (xflags & XFS_XFLAG_NOATIME)
900 di_flags |= XFS_DIFLAG_NOATIME;
901 if (xflags & XFS_XFLAG_NODUMP)
902 di_flags |= XFS_DIFLAG_NODUMP;
903 if (xflags & XFS_XFLAG_PROJINHERIT)
904 di_flags |= XFS_DIFLAG_PROJINHERIT;
905 if (xflags & XFS_XFLAG_NODEFRAG)
906 di_flags |= XFS_DIFLAG_NODEFRAG;
907 if (xflags & XFS_XFLAG_FILESTREAM)
908 di_flags |= XFS_DIFLAG_FILESTREAM;
909 if ((ip->i_d.di_mode & S_IFMT) == S_IFDIR) {
910 if (xflags & XFS_XFLAG_RTINHERIT)
911 di_flags |= XFS_DIFLAG_RTINHERIT;
912 if (xflags & XFS_XFLAG_NOSYMLINKS)
913 di_flags |= XFS_DIFLAG_NOSYMLINKS;
914 if (xflags & XFS_XFLAG_EXTSZINHERIT)
915 di_flags |= XFS_DIFLAG_EXTSZINHERIT;
916 } else if ((ip->i_d.di_mode & S_IFMT) == S_IFREG) {
917 if (xflags & XFS_XFLAG_REALTIME)
918 di_flags |= XFS_DIFLAG_REALTIME;
919 if (xflags & XFS_XFLAG_EXTSIZE)
920 di_flags |= XFS_DIFLAG_EXTSIZE;
921 }
922
923 ip->i_d.di_flags = di_flags;
924}
925
926STATIC void
927xfs_diflags_to_linux(
928 struct xfs_inode *ip)
929{
930 struct inode *inode = XFS_ITOV(ip);
931 unsigned int xflags = xfs_ip2xflags(ip);
932
933 if (xflags & XFS_XFLAG_IMMUTABLE)
934 inode->i_flags |= S_IMMUTABLE;
935 else
936 inode->i_flags &= ~S_IMMUTABLE;
937 if (xflags & XFS_XFLAG_APPEND)
938 inode->i_flags |= S_APPEND;
939 else
940 inode->i_flags &= ~S_APPEND;
941 if (xflags & XFS_XFLAG_SYNC)
942 inode->i_flags |= S_SYNC;
943 else
944 inode->i_flags &= ~S_SYNC;
945 if (xflags & XFS_XFLAG_NOATIME)
946 inode->i_flags |= S_NOATIME;
947 else
948 inode->i_flags &= ~S_NOATIME;
949}
950
951#define FSX_PROJID 1
952#define FSX_EXTSIZE 2
953#define FSX_XFLAGS 4
954#define FSX_NONBLOCK 8
955
956STATIC int
957xfs_ioctl_setattr(
958 xfs_inode_t *ip,
959 struct fsxattr *fa,
960 int mask)
961{
962 struct xfs_mount *mp = ip->i_mount;
963 struct xfs_trans *tp;
964 unsigned int lock_flags = 0;
965 struct xfs_dquot *udqp = NULL, *gdqp = NULL;
966 struct xfs_dquot *olddquot = NULL;
967 int code;
968
969 xfs_itrace_entry(ip);
970
971 if (mp->m_flags & XFS_MOUNT_RDONLY)
972 return XFS_ERROR(EROFS);
973 if (XFS_FORCED_SHUTDOWN(mp))
974 return XFS_ERROR(EIO);
975
976 /*
977 * If disk quotas is on, we make sure that the dquots do exist on disk,
978 * before we start any other transactions. Trying to do this later
979 * is messy. We don't care to take a readlock to look at the ids
980 * in inode here, because we can't hold it across the trans_reserve.
981 * If the IDs do change before we take the ilock, we're covered
982 * because the i_*dquot fields will get updated anyway.
983 */
984 if (XFS_IS_QUOTA_ON(mp) && (mask & FSX_PROJID)) {
985 code = XFS_QM_DQVOPALLOC(mp, ip, ip->i_d.di_uid,
986 ip->i_d.di_gid, fa->fsx_projid,
987 XFS_QMOPT_PQUOTA, &udqp, &gdqp);
988 if (code)
989 return code;
990 }
991
992 /*
993 * For the other attributes, we acquire the inode lock and
994 * first do an error checking pass.
995 */
996 tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
997 code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
998 if (code)
999 goto error_return;
1000
1001 lock_flags = XFS_ILOCK_EXCL;
1002 xfs_ilock(ip, lock_flags);
1003
1004 /*
1005 * CAP_FOWNER overrides the following restrictions:
1006 *
1007 * The user ID of the calling process must be equal
1008 * to the file owner ID, except in cases where the
1009 * CAP_FSETID capability is applicable.
1010 */
1011 if (current->fsuid != ip->i_d.di_uid && !capable(CAP_FOWNER)) {
1012 code = XFS_ERROR(EPERM);
1013 goto error_return;
1014 }
1015
1016 /*
1017 * Do a quota reservation only if projid is actually going to change.
1018 */
1019 if (mask & FSX_PROJID) {
1020 if (XFS_IS_PQUOTA_ON(mp) &&
1021 ip->i_d.di_projid != fa->fsx_projid) {
1022 ASSERT(tp);
1023 code = XFS_QM_DQVOPCHOWNRESV(mp, tp, ip, udqp, gdqp,
1024 capable(CAP_FOWNER) ?
1025 XFS_QMOPT_FORCE_RES : 0);
1026 if (code) /* out of quota */
1027 goto error_return;
1028 }
1029 }
1030
1031 if (mask & FSX_EXTSIZE) {
1032 /*
1033 * Can't change extent size if any extents are allocated.
1034 */
1035 if (ip->i_d.di_nextents &&
1036 ((ip->i_d.di_extsize << mp->m_sb.sb_blocklog) !=
1037 fa->fsx_extsize)) {
1038 code = XFS_ERROR(EINVAL); /* EFBIG? */
1039 goto error_return;
1040 }
1041
1042 /*
1043 * Extent size must be a multiple of the appropriate block
1044 * size, if set at all.
1045 */
1046 if (fa->fsx_extsize != 0) {
1047 xfs_extlen_t size;
1048
1049 if (XFS_IS_REALTIME_INODE(ip) ||
1050 ((mask & FSX_XFLAGS) &&
1051 (fa->fsx_xflags & XFS_XFLAG_REALTIME))) {
1052 size = mp->m_sb.sb_rextsize <<
1053 mp->m_sb.sb_blocklog;
1054 } else {
1055 size = mp->m_sb.sb_blocksize;
1056 }
1057
1058 if (fa->fsx_extsize % size) {
1059 code = XFS_ERROR(EINVAL);
1060 goto error_return;
1061 }
1062 }
1063 }
1064
1065
1066 if (mask & FSX_XFLAGS) {
1067 /*
1068 * Can't change realtime flag if any extents are allocated.
1069 */
1070 if ((ip->i_d.di_nextents || ip->i_delayed_blks) &&
1071 (XFS_IS_REALTIME_INODE(ip)) !=
1072 (fa->fsx_xflags & XFS_XFLAG_REALTIME)) {
1073 code = XFS_ERROR(EINVAL); /* EFBIG? */
1074 goto error_return;
1075 }
1076
1077 /*
1078 * If realtime flag is set then must have realtime data.
1079 */
1080 if ((fa->fsx_xflags & XFS_XFLAG_REALTIME)) {
1081 if ((mp->m_sb.sb_rblocks == 0) ||
1082 (mp->m_sb.sb_rextsize == 0) ||
1083 (ip->i_d.di_extsize % mp->m_sb.sb_rextsize)) {
1084 code = XFS_ERROR(EINVAL);
1085 goto error_return;
1086 }
1087 }
1088
1089 /*
1090 * Can't modify an immutable/append-only file unless
1091 * we have appropriate permission.
1092 */
1093 if ((ip->i_d.di_flags &
1094 (XFS_DIFLAG_IMMUTABLE|XFS_DIFLAG_APPEND) ||
1095 (fa->fsx_xflags &
1096 (XFS_XFLAG_IMMUTABLE | XFS_XFLAG_APPEND))) &&
1097 !capable(CAP_LINUX_IMMUTABLE)) {
1098 code = XFS_ERROR(EPERM);
1099 goto error_return;
1100 }
1101 }
1102
1103 xfs_trans_ijoin(tp, ip, lock_flags);
1104 xfs_trans_ihold(tp, ip);
1105
1106 /*
1107 * Change file ownership. Must be the owner or privileged.
1108 * If the system was configured with the "restricted_chown"
1109 * option, the owner is not permitted to give away the file,
1110 * and can change the group id only to a group of which he
1111 * or she is a member.
1112 */
1113 if (mask & FSX_PROJID) {
1114 /*
1115 * CAP_FSETID overrides the following restrictions:
1116 *
1117 * The set-user-ID and set-group-ID bits of a file will be
1118 * cleared upon successful return from chown()
1119 */
1120 if ((ip->i_d.di_mode & (S_ISUID|S_ISGID)) &&
1121 !capable(CAP_FSETID))
1122 ip->i_d.di_mode &= ~(S_ISUID|S_ISGID);
1123
1124 /*
1125 * Change the ownerships and register quota modifications
1126 * in the transaction.
1127 */
1128 if (ip->i_d.di_projid != fa->fsx_projid) {
1129 if (XFS_IS_PQUOTA_ON(mp)) {
1130 olddquot = XFS_QM_DQVOPCHOWN(mp, tp, ip,
1131 &ip->i_gdquot, gdqp);
1132 }
1133 ip->i_d.di_projid = fa->fsx_projid;
1134
1135 /*
1136 * We may have to rev the inode as well as
1137 * the superblock version number since projids didn't
1138 * exist before DINODE_VERSION_2 and SB_VERSION_NLINK.
1139 */
1140 if (ip->i_d.di_version == XFS_DINODE_VERSION_1)
1141 xfs_bump_ino_vers2(tp, ip);
1142 }
1143
1144 }
1145
1146 if (mask & FSX_EXTSIZE)
1147 ip->i_d.di_extsize = fa->fsx_extsize >> mp->m_sb.sb_blocklog;
1148 if (mask & FSX_XFLAGS) {
1149 xfs_set_diflags(ip, fa->fsx_xflags);
1150 xfs_diflags_to_linux(ip);
1151 }
1152
1153 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
1154 xfs_ichgtime(ip, XFS_ICHGTIME_CHG);
1155
1156 XFS_STATS_INC(xs_ig_attrchg);
1157
1158 /*
1159 * If this is a synchronous mount, make sure that the
1160 * transaction goes to disk before returning to the user.
1161 * This is slightly sub-optimal in that truncates require
1162 * two sync transactions instead of one for wsync filesystems.
1163 * One for the truncate and one for the timestamps since we
1164 * don't want to change the timestamps unless we're sure the
1165 * truncate worked. Truncates are less than 1% of the laddis
1166 * mix so this probably isn't worth the trouble to optimize.
1167 */
1168 if (mp->m_flags & XFS_MOUNT_WSYNC)
1169 xfs_trans_set_sync(tp);
1170 code = xfs_trans_commit(tp, 0);
1171 xfs_iunlock(ip, lock_flags);
1172
1173 /*
1174 * Release any dquot(s) the inode had kept before chown.
1175 */
1176 XFS_QM_DQRELE(mp, olddquot);
1177 XFS_QM_DQRELE(mp, udqp);
1178 XFS_QM_DQRELE(mp, gdqp);
1179
1180 if (code)
1181 return code;
1182
1183 if (DM_EVENT_ENABLED(ip, DM_EVENT_ATTRIBUTE)) {
1184 XFS_SEND_NAMESP(mp, DM_EVENT_ATTRIBUTE, ip, DM_RIGHT_NULL,
1185 NULL, DM_RIGHT_NULL, NULL, NULL, 0, 0,
1186 (mask & FSX_NONBLOCK) ? DM_FLAGS_NDELAY : 0);
1187 }
1188
1189 return 0;
1190
1191 error_return:
1192 XFS_QM_DQRELE(mp, udqp);
1193 XFS_QM_DQRELE(mp, gdqp);
1194 xfs_trans_cancel(tp, 0);
1195 if (lock_flags)
1196 xfs_iunlock(ip, lock_flags);
1197 return code;
1198}
1199
876STATIC int 1200STATIC int
877xfs_ioc_fssetxattr( 1201xfs_ioc_fssetxattr(
878 xfs_inode_t *ip, 1202 xfs_inode_t *ip,
@@ -880,31 +1204,16 @@ xfs_ioc_fssetxattr(
880 void __user *arg) 1204 void __user *arg)
881{ 1205{
882 struct fsxattr fa; 1206 struct fsxattr fa;
883 struct bhv_vattr *vattr; 1207 unsigned int mask;
884 int error;
885 int attr_flags;
886 1208
887 if (copy_from_user(&fa, arg, sizeof(fa))) 1209 if (copy_from_user(&fa, arg, sizeof(fa)))
888 return -EFAULT; 1210 return -EFAULT;
889 1211
890 vattr = kmalloc(sizeof(*vattr), GFP_KERNEL); 1212 mask = FSX_XFLAGS | FSX_EXTSIZE | FSX_PROJID;
891 if (unlikely(!vattr))
892 return -ENOMEM;
893
894 attr_flags = 0;
895 if (filp->f_flags & (O_NDELAY|O_NONBLOCK)) 1213 if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
896 attr_flags |= ATTR_NONBLOCK; 1214 mask |= FSX_NONBLOCK;
897
898 vattr->va_mask = XFS_AT_XFLAGS | XFS_AT_EXTSIZE | XFS_AT_PROJID;
899 vattr->va_xflags = fa.fsx_xflags;
900 vattr->va_extsize = fa.fsx_extsize;
901 vattr->va_projid = fa.fsx_projid;
902 1215
903 error = -xfs_setattr(ip, vattr, attr_flags, NULL); 1216 return -xfs_ioctl_setattr(ip, &fa, mask);
904 if (!error)
905 vn_revalidate(XFS_ITOV(ip)); /* update flags */
906 kfree(vattr);
907 return 0;
908} 1217}
909 1218
910STATIC int 1219STATIC int
@@ -926,10 +1235,9 @@ xfs_ioc_setxflags(
926 struct file *filp, 1235 struct file *filp,
927 void __user *arg) 1236 void __user *arg)
928{ 1237{
929 struct bhv_vattr *vattr; 1238 struct fsxattr fa;
930 unsigned int flags; 1239 unsigned int flags;
931 int attr_flags; 1240 unsigned int mask;
932 int error;
933 1241
934 if (copy_from_user(&flags, arg, sizeof(flags))) 1242 if (copy_from_user(&flags, arg, sizeof(flags)))
935 return -EFAULT; 1243 return -EFAULT;
@@ -939,22 +1247,12 @@ xfs_ioc_setxflags(
939 FS_SYNC_FL)) 1247 FS_SYNC_FL))
940 return -EOPNOTSUPP; 1248 return -EOPNOTSUPP;
941 1249
942 vattr = kmalloc(sizeof(*vattr), GFP_KERNEL); 1250 mask = FSX_XFLAGS;
943 if (unlikely(!vattr))
944 return -ENOMEM;
945
946 attr_flags = 0;
947 if (filp->f_flags & (O_NDELAY|O_NONBLOCK)) 1251 if (filp->f_flags & (O_NDELAY|O_NONBLOCK))
948 attr_flags |= ATTR_NONBLOCK; 1252 mask |= FSX_NONBLOCK;
949 1253 fa.fsx_xflags = xfs_merge_ioc_xflags(flags, xfs_ip2xflags(ip));
950 vattr->va_mask = XFS_AT_XFLAGS;
951 vattr->va_xflags = xfs_merge_ioc_xflags(flags, xfs_ip2xflags(ip));
952 1254
953 error = -xfs_setattr(ip, vattr, attr_flags, NULL); 1255 return -xfs_ioctl_setattr(ip, &fa, mask);
954 if (likely(!error))
955 vn_revalidate(XFS_ITOV(ip)); /* update flags */
956 kfree(vattr);
957 return error;
958} 1256}
959 1257
960STATIC int 1258STATIC int
diff --git a/fs/xfs/linux-2.6/xfs_iops.c b/fs/xfs/linux-2.6/xfs_iops.c
index 5fc61c824bb9..e88f51028086 100644
--- a/fs/xfs/linux-2.6/xfs_iops.c
+++ b/fs/xfs/linux-2.6/xfs_iops.c
@@ -181,23 +181,6 @@ xfs_ichgtime_fast(
181 mark_inode_dirty_sync(inode); 181 mark_inode_dirty_sync(inode);
182} 182}
183 183
184
185/*
186 * Pull the link count and size up from the xfs inode to the linux inode
187 */
188STATIC void
189xfs_validate_fields(
190 struct inode *inode)
191{
192 struct xfs_inode *ip = XFS_I(inode);
193 loff_t size;
194
195 /* we're under i_sem so i_size can't change under us */
196 size = XFS_ISIZE(ip);
197 if (i_size_read(inode) != size)
198 i_size_write(inode, size);
199}
200
201/* 184/*
202 * Hook in SELinux. This is not quite correct yet, what we really need 185 * Hook in SELinux. This is not quite correct yet, what we really need
203 * here (as we do for default ACLs) is a mechanism by which creation of 186 * here (as we do for default ACLs) is a mechanism by which creation of
@@ -245,8 +228,7 @@ STATIC void
245xfs_cleanup_inode( 228xfs_cleanup_inode(
246 struct inode *dir, 229 struct inode *dir,
247 struct inode *inode, 230 struct inode *inode,
248 struct dentry *dentry, 231 struct dentry *dentry)
249 int mode)
250{ 232{
251 struct xfs_name teardown; 233 struct xfs_name teardown;
252 234
@@ -257,10 +239,7 @@ xfs_cleanup_inode(
257 */ 239 */
258 xfs_dentry_to_name(&teardown, dentry); 240 xfs_dentry_to_name(&teardown, dentry);
259 241
260 if (S_ISDIR(mode)) 242 xfs_remove(XFS_I(dir), &teardown, XFS_I(inode));
261 xfs_rmdir(XFS_I(dir), &teardown, XFS_I(inode));
262 else
263 xfs_remove(XFS_I(dir), &teardown, XFS_I(inode));
264 iput(inode); 243 iput(inode);
265} 244}
266 245
@@ -275,7 +254,7 @@ xfs_vn_mknod(
275 struct xfs_inode *ip = NULL; 254 struct xfs_inode *ip = NULL;
276 xfs_acl_t *default_acl = NULL; 255 xfs_acl_t *default_acl = NULL;
277 struct xfs_name name; 256 struct xfs_name name;
278 attrexists_t test_default_acl = _ACL_DEFAULT_EXISTS; 257 int (*test_default_acl)(struct inode *) = _ACL_DEFAULT_EXISTS;
279 int error; 258 int error;
280 259
281 /* 260 /*
@@ -335,14 +314,11 @@ xfs_vn_mknod(
335 } 314 }
336 315
337 316
338 if (S_ISDIR(mode))
339 xfs_validate_fields(inode);
340 d_instantiate(dentry, inode); 317 d_instantiate(dentry, inode);
341 xfs_validate_fields(dir);
342 return -error; 318 return -error;
343 319
344 out_cleanup_inode: 320 out_cleanup_inode:
345 xfs_cleanup_inode(dir, inode, dentry, mode); 321 xfs_cleanup_inode(dir, inode, dentry);
346 out_free_acl: 322 out_free_acl:
347 if (default_acl) 323 if (default_acl)
348 _ACL_FREE(default_acl); 324 _ACL_FREE(default_acl);
@@ -382,7 +358,7 @@ xfs_vn_lookup(
382 return ERR_PTR(-ENAMETOOLONG); 358 return ERR_PTR(-ENAMETOOLONG);
383 359
384 xfs_dentry_to_name(&name, dentry); 360 xfs_dentry_to_name(&name, dentry);
385 error = xfs_lookup(XFS_I(dir), &name, &cip); 361 error = xfs_lookup(XFS_I(dir), &name, &cip, NULL);
386 if (unlikely(error)) { 362 if (unlikely(error)) {
387 if (unlikely(error != ENOENT)) 363 if (unlikely(error != ENOENT))
388 return ERR_PTR(-error); 364 return ERR_PTR(-error);
@@ -393,6 +369,46 @@ xfs_vn_lookup(
393 return d_splice_alias(cip->i_vnode, dentry); 369 return d_splice_alias(cip->i_vnode, dentry);
394} 370}
395 371
372STATIC struct dentry *
373xfs_vn_ci_lookup(
374 struct inode *dir,
375 struct dentry *dentry,
376 struct nameidata *nd)
377{
378 struct xfs_inode *ip;
379 struct xfs_name xname;
380 struct xfs_name ci_name;
381 struct qstr dname;
382 int error;
383
384 if (dentry->d_name.len >= MAXNAMELEN)
385 return ERR_PTR(-ENAMETOOLONG);
386
387 xfs_dentry_to_name(&xname, dentry);
388 error = xfs_lookup(XFS_I(dir), &xname, &ip, &ci_name);
389 if (unlikely(error)) {
390 if (unlikely(error != ENOENT))
391 return ERR_PTR(-error);
392 /*
393 * call d_add(dentry, NULL) here when d_drop_negative_children
394 * is called in xfs_vn_mknod (ie. allow negative dentries
395 * with CI filesystems).
396 */
397 return NULL;
398 }
399
400 /* if exact match, just splice and exit */
401 if (!ci_name.name)
402 return d_splice_alias(ip->i_vnode, dentry);
403
404 /* else case-insensitive match... */
405 dname.name = ci_name.name;
406 dname.len = ci_name.len;
407 dentry = d_add_ci(ip->i_vnode, dentry, &dname);
408 kmem_free(ci_name.name);
409 return dentry;
410}
411
396STATIC int 412STATIC int
397xfs_vn_link( 413xfs_vn_link(
398 struct dentry *old_dentry, 414 struct dentry *old_dentry,
@@ -414,7 +430,6 @@ xfs_vn_link(
414 } 430 }
415 431
416 xfs_iflags_set(XFS_I(dir), XFS_IMODIFIED); 432 xfs_iflags_set(XFS_I(dir), XFS_IMODIFIED);
417 xfs_validate_fields(inode);
418 d_instantiate(dentry, inode); 433 d_instantiate(dentry, inode);
419 return 0; 434 return 0;
420} 435}
@@ -424,19 +439,23 @@ xfs_vn_unlink(
424 struct inode *dir, 439 struct inode *dir,
425 struct dentry *dentry) 440 struct dentry *dentry)
426{ 441{
427 struct inode *inode;
428 struct xfs_name name; 442 struct xfs_name name;
429 int error; 443 int error;
430 444
431 inode = dentry->d_inode;
432 xfs_dentry_to_name(&name, dentry); 445 xfs_dentry_to_name(&name, dentry);
433 446
434 error = xfs_remove(XFS_I(dir), &name, XFS_I(inode)); 447 error = -xfs_remove(XFS_I(dir), &name, XFS_I(dentry->d_inode));
435 if (likely(!error)) { 448 if (error)
436 xfs_validate_fields(dir); /* size needs update */ 449 return error;
437 xfs_validate_fields(inode); 450
438 } 451 /*
439 return -error; 452 * With unlink, the VFS makes the dentry "negative": no inode,
453 * but still hashed. This is incompatible with case-insensitive
454 * mode, so invalidate (unhash) the dentry in CI-mode.
455 */
456 if (xfs_sb_version_hasasciici(&XFS_M(dir->i_sb)->m_sb))
457 d_invalidate(dentry);
458 return 0;
440} 459}
441 460
442STATIC int 461STATIC int
@@ -466,36 +485,15 @@ xfs_vn_symlink(
466 goto out_cleanup_inode; 485 goto out_cleanup_inode;
467 486
468 d_instantiate(dentry, inode); 487 d_instantiate(dentry, inode);
469 xfs_validate_fields(dir);
470 xfs_validate_fields(inode);
471 return 0; 488 return 0;
472 489
473 out_cleanup_inode: 490 out_cleanup_inode:
474 xfs_cleanup_inode(dir, inode, dentry, 0); 491 xfs_cleanup_inode(dir, inode, dentry);
475 out: 492 out:
476 return -error; 493 return -error;
477} 494}
478 495
479STATIC int 496STATIC int
480xfs_vn_rmdir(
481 struct inode *dir,
482 struct dentry *dentry)
483{
484 struct inode *inode = dentry->d_inode;
485 struct xfs_name name;
486 int error;
487
488 xfs_dentry_to_name(&name, dentry);
489
490 error = xfs_rmdir(XFS_I(dir), &name, XFS_I(inode));
491 if (likely(!error)) {
492 xfs_validate_fields(inode);
493 xfs_validate_fields(dir);
494 }
495 return -error;
496}
497
498STATIC int
499xfs_vn_rename( 497xfs_vn_rename(
500 struct inode *odir, 498 struct inode *odir,
501 struct dentry *odentry, 499 struct dentry *odentry,
@@ -505,22 +503,13 @@ xfs_vn_rename(
505 struct inode *new_inode = ndentry->d_inode; 503 struct inode *new_inode = ndentry->d_inode;
506 struct xfs_name oname; 504 struct xfs_name oname;
507 struct xfs_name nname; 505 struct xfs_name nname;
508 int error;
509 506
510 xfs_dentry_to_name(&oname, odentry); 507 xfs_dentry_to_name(&oname, odentry);
511 xfs_dentry_to_name(&nname, ndentry); 508 xfs_dentry_to_name(&nname, ndentry);
512 509
513 error = xfs_rename(XFS_I(odir), &oname, XFS_I(odentry->d_inode), 510 return -xfs_rename(XFS_I(odir), &oname, XFS_I(odentry->d_inode),
514 XFS_I(ndir), &nname, new_inode ? 511 XFS_I(ndir), &nname, new_inode ?
515 XFS_I(new_inode) : NULL); 512 XFS_I(new_inode) : NULL);
516 if (likely(!error)) {
517 if (new_inode)
518 xfs_validate_fields(new_inode);
519 xfs_validate_fields(odir);
520 if (ndir != odir)
521 xfs_validate_fields(ndir);
522 }
523 return -error;
524} 513}
525 514
526/* 515/*
@@ -659,57 +648,9 @@ xfs_vn_getattr(
659STATIC int 648STATIC int
660xfs_vn_setattr( 649xfs_vn_setattr(
661 struct dentry *dentry, 650 struct dentry *dentry,
662 struct iattr *attr) 651 struct iattr *iattr)
663{ 652{
664 struct inode *inode = dentry->d_inode; 653 return -xfs_setattr(XFS_I(dentry->d_inode), iattr, 0, NULL);
665 unsigned int ia_valid = attr->ia_valid;
666 bhv_vattr_t vattr = { 0 };
667 int flags = 0;
668 int error;
669
670 if (ia_valid & ATTR_UID) {
671 vattr.va_mask |= XFS_AT_UID;
672 vattr.va_uid = attr->ia_uid;
673 }
674 if (ia_valid & ATTR_GID) {
675 vattr.va_mask |= XFS_AT_GID;
676 vattr.va_gid = attr->ia_gid;
677 }
678 if (ia_valid & ATTR_SIZE) {
679 vattr.va_mask |= XFS_AT_SIZE;
680 vattr.va_size = attr->ia_size;
681 }
682 if (ia_valid & ATTR_ATIME) {
683 vattr.va_mask |= XFS_AT_ATIME;
684 vattr.va_atime = attr->ia_atime;
685 inode->i_atime = attr->ia_atime;
686 }
687 if (ia_valid & ATTR_MTIME) {
688 vattr.va_mask |= XFS_AT_MTIME;
689 vattr.va_mtime = attr->ia_mtime;
690 }
691 if (ia_valid & ATTR_CTIME) {
692 vattr.va_mask |= XFS_AT_CTIME;
693 vattr.va_ctime = attr->ia_ctime;
694 }
695 if (ia_valid & ATTR_MODE) {
696 vattr.va_mask |= XFS_AT_MODE;
697 vattr.va_mode = attr->ia_mode;
698 if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID))
699 inode->i_mode &= ~S_ISGID;
700 }
701
702 if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET))
703 flags |= ATTR_UTIME;
704#ifdef ATTR_NO_BLOCK
705 if ((ia_valid & ATTR_NO_BLOCK))
706 flags |= ATTR_NONBLOCK;
707#endif
708
709 error = xfs_setattr(XFS_I(inode), &vattr, flags, NULL);
710 if (likely(!error))
711 vn_revalidate(vn_from_inode(inode));
712 return -error;
713} 654}
714 655
715/* 656/*
@@ -727,109 +668,6 @@ xfs_vn_truncate(
727 WARN_ON(error); 668 WARN_ON(error);
728} 669}
729 670
730STATIC int
731xfs_vn_setxattr(
732 struct dentry *dentry,
733 const char *name,
734 const void *data,
735 size_t size,
736 int flags)
737{
738 bhv_vnode_t *vp = vn_from_inode(dentry->d_inode);
739 char *attr = (char *)name;
740 attrnames_t *namesp;
741 int xflags = 0;
742 int error;
743
744 namesp = attr_lookup_namespace(attr, attr_namespaces, ATTR_NAMECOUNT);
745 if (!namesp)
746 return -EOPNOTSUPP;
747 attr += namesp->attr_namelen;
748 error = namesp->attr_capable(vp, NULL);
749 if (error)
750 return error;
751
752 /* Convert Linux syscall to XFS internal ATTR flags */
753 if (flags & XATTR_CREATE)
754 xflags |= ATTR_CREATE;
755 if (flags & XATTR_REPLACE)
756 xflags |= ATTR_REPLACE;
757 xflags |= namesp->attr_flag;
758 return namesp->attr_set(vp, attr, (void *)data, size, xflags);
759}
760
761STATIC ssize_t
762xfs_vn_getxattr(
763 struct dentry *dentry,
764 const char *name,
765 void *data,
766 size_t size)
767{
768 bhv_vnode_t *vp = vn_from_inode(dentry->d_inode);
769 char *attr = (char *)name;
770 attrnames_t *namesp;
771 int xflags = 0;
772 ssize_t error;
773
774 namesp = attr_lookup_namespace(attr, attr_namespaces, ATTR_NAMECOUNT);
775 if (!namesp)
776 return -EOPNOTSUPP;
777 attr += namesp->attr_namelen;
778 error = namesp->attr_capable(vp, NULL);
779 if (error)
780 return error;
781
782 /* Convert Linux syscall to XFS internal ATTR flags */
783 if (!size) {
784 xflags |= ATTR_KERNOVAL;
785 data = NULL;
786 }
787 xflags |= namesp->attr_flag;
788 return namesp->attr_get(vp, attr, (void *)data, size, xflags);
789}
790
791STATIC ssize_t
792xfs_vn_listxattr(
793 struct dentry *dentry,
794 char *data,
795 size_t size)
796{
797 bhv_vnode_t *vp = vn_from_inode(dentry->d_inode);
798 int error, xflags = ATTR_KERNAMELS;
799 ssize_t result;
800
801 if (!size)
802 xflags |= ATTR_KERNOVAL;
803 xflags |= capable(CAP_SYS_ADMIN) ? ATTR_KERNFULLS : ATTR_KERNORMALS;
804
805 error = attr_generic_list(vp, data, size, xflags, &result);
806 if (error < 0)
807 return error;
808 return result;
809}
810
811STATIC int
812xfs_vn_removexattr(
813 struct dentry *dentry,
814 const char *name)
815{
816 bhv_vnode_t *vp = vn_from_inode(dentry->d_inode);
817 char *attr = (char *)name;
818 attrnames_t *namesp;
819 int xflags = 0;
820 int error;
821
822 namesp = attr_lookup_namespace(attr, attr_namespaces, ATTR_NAMECOUNT);
823 if (!namesp)
824 return -EOPNOTSUPP;
825 attr += namesp->attr_namelen;
826 error = namesp->attr_capable(vp, NULL);
827 if (error)
828 return error;
829 xflags |= namesp->attr_flag;
830 return namesp->attr_remove(vp, attr, xflags);
831}
832
833STATIC long 671STATIC long
834xfs_vn_fallocate( 672xfs_vn_fallocate(
835 struct inode *inode, 673 struct inode *inode,
@@ -853,18 +691,18 @@ xfs_vn_fallocate(
853 691
854 xfs_ilock(ip, XFS_IOLOCK_EXCL); 692 xfs_ilock(ip, XFS_IOLOCK_EXCL);
855 error = xfs_change_file_space(ip, XFS_IOC_RESVSP, &bf, 693 error = xfs_change_file_space(ip, XFS_IOC_RESVSP, &bf,
856 0, NULL, ATTR_NOLOCK); 694 0, NULL, XFS_ATTR_NOLOCK);
857 if (!error && !(mode & FALLOC_FL_KEEP_SIZE) && 695 if (!error && !(mode & FALLOC_FL_KEEP_SIZE) &&
858 offset + len > i_size_read(inode)) 696 offset + len > i_size_read(inode))
859 new_size = offset + len; 697 new_size = offset + len;
860 698
861 /* Change file size if needed */ 699 /* Change file size if needed */
862 if (new_size) { 700 if (new_size) {
863 bhv_vattr_t va; 701 struct iattr iattr;
864 702
865 va.va_mask = XFS_AT_SIZE; 703 iattr.ia_valid = ATTR_SIZE;
866 va.va_size = new_size; 704 iattr.ia_size = new_size;
867 error = xfs_setattr(ip, &va, ATTR_NOLOCK, NULL); 705 error = xfs_setattr(ip, &iattr, XFS_ATTR_NOLOCK, NULL);
868 } 706 }
869 707
870 xfs_iunlock(ip, XFS_IOLOCK_EXCL); 708 xfs_iunlock(ip, XFS_IOLOCK_EXCL);
@@ -877,10 +715,10 @@ const struct inode_operations xfs_inode_operations = {
877 .truncate = xfs_vn_truncate, 715 .truncate = xfs_vn_truncate,
878 .getattr = xfs_vn_getattr, 716 .getattr = xfs_vn_getattr,
879 .setattr = xfs_vn_setattr, 717 .setattr = xfs_vn_setattr,
880 .setxattr = xfs_vn_setxattr, 718 .setxattr = generic_setxattr,
881 .getxattr = xfs_vn_getxattr, 719 .getxattr = generic_getxattr,
720 .removexattr = generic_removexattr,
882 .listxattr = xfs_vn_listxattr, 721 .listxattr = xfs_vn_listxattr,
883 .removexattr = xfs_vn_removexattr,
884 .fallocate = xfs_vn_fallocate, 722 .fallocate = xfs_vn_fallocate,
885}; 723};
886 724
@@ -891,16 +729,47 @@ const struct inode_operations xfs_dir_inode_operations = {
891 .unlink = xfs_vn_unlink, 729 .unlink = xfs_vn_unlink,
892 .symlink = xfs_vn_symlink, 730 .symlink = xfs_vn_symlink,
893 .mkdir = xfs_vn_mkdir, 731 .mkdir = xfs_vn_mkdir,
894 .rmdir = xfs_vn_rmdir, 732 /*
733 * Yes, XFS uses the same method for rmdir and unlink.
734 *
735 * There are some subtile differences deeper in the code,
736 * but we use S_ISDIR to check for those.
737 */
738 .rmdir = xfs_vn_unlink,
739 .mknod = xfs_vn_mknod,
740 .rename = xfs_vn_rename,
741 .permission = xfs_vn_permission,
742 .getattr = xfs_vn_getattr,
743 .setattr = xfs_vn_setattr,
744 .setxattr = generic_setxattr,
745 .getxattr = generic_getxattr,
746 .removexattr = generic_removexattr,
747 .listxattr = xfs_vn_listxattr,
748};
749
750const struct inode_operations xfs_dir_ci_inode_operations = {
751 .create = xfs_vn_create,
752 .lookup = xfs_vn_ci_lookup,
753 .link = xfs_vn_link,
754 .unlink = xfs_vn_unlink,
755 .symlink = xfs_vn_symlink,
756 .mkdir = xfs_vn_mkdir,
757 /*
758 * Yes, XFS uses the same method for rmdir and unlink.
759 *
760 * There are some subtile differences deeper in the code,
761 * but we use S_ISDIR to check for those.
762 */
763 .rmdir = xfs_vn_unlink,
895 .mknod = xfs_vn_mknod, 764 .mknod = xfs_vn_mknod,
896 .rename = xfs_vn_rename, 765 .rename = xfs_vn_rename,
897 .permission = xfs_vn_permission, 766 .permission = xfs_vn_permission,
898 .getattr = xfs_vn_getattr, 767 .getattr = xfs_vn_getattr,
899 .setattr = xfs_vn_setattr, 768 .setattr = xfs_vn_setattr,
900 .setxattr = xfs_vn_setxattr, 769 .setxattr = generic_setxattr,
901 .getxattr = xfs_vn_getxattr, 770 .getxattr = generic_getxattr,
771 .removexattr = generic_removexattr,
902 .listxattr = xfs_vn_listxattr, 772 .listxattr = xfs_vn_listxattr,
903 .removexattr = xfs_vn_removexattr,
904}; 773};
905 774
906const struct inode_operations xfs_symlink_inode_operations = { 775const struct inode_operations xfs_symlink_inode_operations = {
@@ -910,8 +779,8 @@ const struct inode_operations xfs_symlink_inode_operations = {
910 .permission = xfs_vn_permission, 779 .permission = xfs_vn_permission,
911 .getattr = xfs_vn_getattr, 780 .getattr = xfs_vn_getattr,
912 .setattr = xfs_vn_setattr, 781 .setattr = xfs_vn_setattr,
913 .setxattr = xfs_vn_setxattr, 782 .setxattr = generic_setxattr,
914 .getxattr = xfs_vn_getxattr, 783 .getxattr = generic_getxattr,
784 .removexattr = generic_removexattr,
915 .listxattr = xfs_vn_listxattr, 785 .listxattr = xfs_vn_listxattr,
916 .removexattr = xfs_vn_removexattr,
917}; 786};
diff --git a/fs/xfs/linux-2.6/xfs_iops.h b/fs/xfs/linux-2.6/xfs_iops.h
index 14d0deb7afff..d97ba934a2ac 100644
--- a/fs/xfs/linux-2.6/xfs_iops.h
+++ b/fs/xfs/linux-2.6/xfs_iops.h
@@ -20,12 +20,14 @@
20 20
21extern const struct inode_operations xfs_inode_operations; 21extern const struct inode_operations xfs_inode_operations;
22extern const struct inode_operations xfs_dir_inode_operations; 22extern const struct inode_operations xfs_dir_inode_operations;
23extern const struct inode_operations xfs_dir_ci_inode_operations;
23extern const struct inode_operations xfs_symlink_inode_operations; 24extern const struct inode_operations xfs_symlink_inode_operations;
24 25
25extern const struct file_operations xfs_file_operations; 26extern const struct file_operations xfs_file_operations;
26extern const struct file_operations xfs_dir_file_operations; 27extern const struct file_operations xfs_dir_file_operations;
27extern const struct file_operations xfs_invis_file_operations; 28extern const struct file_operations xfs_invis_file_operations;
28 29
30extern ssize_t xfs_vn_listxattr(struct dentry *, char *data, size_t size);
29 31
30struct xfs_inode; 32struct xfs_inode;
31extern void xfs_ichgtime(struct xfs_inode *, int); 33extern void xfs_ichgtime(struct xfs_inode *, int);
diff --git a/fs/xfs/linux-2.6/xfs_linux.h b/fs/xfs/linux-2.6/xfs_linux.h
index 4edc46915b57..4d45d9351a6c 100644
--- a/fs/xfs/linux-2.6/xfs_linux.h
+++ b/fs/xfs/linux-2.6/xfs_linux.h
@@ -76,6 +76,7 @@
76#include <linux/log2.h> 76#include <linux/log2.h>
77#include <linux/spinlock.h> 77#include <linux/spinlock.h>
78#include <linux/random.h> 78#include <linux/random.h>
79#include <linux/ctype.h>
79 80
80#include <asm/page.h> 81#include <asm/page.h>
81#include <asm/div64.h> 82#include <asm/div64.h>
@@ -299,4 +300,11 @@ static inline __uint64_t howmany_64(__uint64_t x, __uint32_t y)
299 return x; 300 return x;
300} 301}
301 302
303/* ARM old ABI has some weird alignment/padding */
304#if defined(__arm__) && !defined(__ARM_EABI__)
305#define __arch_pack __attribute__((packed))
306#else
307#define __arch_pack
308#endif
309
302#endif /* __XFS_LINUX__ */ 310#endif /* __XFS_LINUX__ */
diff --git a/fs/xfs/linux-2.6/xfs_stats.c b/fs/xfs/linux-2.6/xfs_stats.c
index e480b6102051..3d5b67c075c7 100644
--- a/fs/xfs/linux-2.6/xfs_stats.c
+++ b/fs/xfs/linux-2.6/xfs_stats.c
@@ -98,12 +98,21 @@ xfs_read_xfsstats(
98 return len; 98 return len;
99} 99}
100 100
101void 101int
102xfs_init_procfs(void) 102xfs_init_procfs(void)
103{ 103{
104 if (!proc_mkdir("fs/xfs", NULL)) 104 if (!proc_mkdir("fs/xfs", NULL))
105 return; 105 goto out;
106 create_proc_read_entry("fs/xfs/stat", 0, NULL, xfs_read_xfsstats, NULL); 106
107 if (!create_proc_read_entry("fs/xfs/stat", 0, NULL,
108 xfs_read_xfsstats, NULL))
109 goto out_remove_entry;
110 return 0;
111
112 out_remove_entry:
113 remove_proc_entry("fs/xfs", NULL);
114 out:
115 return -ENOMEM;
107} 116}
108 117
109void 118void
diff --git a/fs/xfs/linux-2.6/xfs_stats.h b/fs/xfs/linux-2.6/xfs_stats.h
index afd0b0d5fdb2..e83820febc9f 100644
--- a/fs/xfs/linux-2.6/xfs_stats.h
+++ b/fs/xfs/linux-2.6/xfs_stats.h
@@ -134,7 +134,7 @@ DECLARE_PER_CPU(struct xfsstats, xfsstats);
134#define XFS_STATS_DEC(v) (per_cpu(xfsstats, current_cpu()).v--) 134#define XFS_STATS_DEC(v) (per_cpu(xfsstats, current_cpu()).v--)
135#define XFS_STATS_ADD(v, inc) (per_cpu(xfsstats, current_cpu()).v += (inc)) 135#define XFS_STATS_ADD(v, inc) (per_cpu(xfsstats, current_cpu()).v += (inc))
136 136
137extern void xfs_init_procfs(void); 137extern int xfs_init_procfs(void);
138extern void xfs_cleanup_procfs(void); 138extern void xfs_cleanup_procfs(void);
139 139
140 140
@@ -144,8 +144,14 @@ extern void xfs_cleanup_procfs(void);
144# define XFS_STATS_DEC(count) 144# define XFS_STATS_DEC(count)
145# define XFS_STATS_ADD(count, inc) 145# define XFS_STATS_ADD(count, inc)
146 146
147static inline void xfs_init_procfs(void) { }; 147static inline int xfs_init_procfs(void)
148static inline void xfs_cleanup_procfs(void) { }; 148{
149 return 0;
150}
151
152static inline void xfs_cleanup_procfs(void)
153{
154}
149 155
150#endif /* !CONFIG_PROC_FS */ 156#endif /* !CONFIG_PROC_FS */
151 157
diff --git a/fs/xfs/linux-2.6/xfs_super.c b/fs/xfs/linux-2.6/xfs_super.c
index 943381284e2e..30ae96397e31 100644
--- a/fs/xfs/linux-2.6/xfs_super.c
+++ b/fs/xfs/linux-2.6/xfs_super.c
@@ -52,6 +52,12 @@
52#include "xfs_version.h" 52#include "xfs_version.h"
53#include "xfs_log_priv.h" 53#include "xfs_log_priv.h"
54#include "xfs_trans_priv.h" 54#include "xfs_trans_priv.h"
55#include "xfs_filestream.h"
56#include "xfs_da_btree.h"
57#include "xfs_dir2_trace.h"
58#include "xfs_extfree_item.h"
59#include "xfs_mru_cache.h"
60#include "xfs_inode_item.h"
55 61
56#include <linux/namei.h> 62#include <linux/namei.h>
57#include <linux/init.h> 63#include <linux/init.h>
@@ -60,6 +66,7 @@
60#include <linux/writeback.h> 66#include <linux/writeback.h>
61#include <linux/kthread.h> 67#include <linux/kthread.h>
62#include <linux/freezer.h> 68#include <linux/freezer.h>
69#include <linux/parser.h>
63 70
64static struct quotactl_ops xfs_quotactl_operations; 71static struct quotactl_ops xfs_quotactl_operations;
65static struct super_operations xfs_super_operations; 72static struct super_operations xfs_super_operations;
@@ -74,7 +81,10 @@ xfs_args_allocate(
74{ 81{
75 struct xfs_mount_args *args; 82 struct xfs_mount_args *args;
76 83
77 args = kmem_zalloc(sizeof(struct xfs_mount_args), KM_SLEEP); 84 args = kzalloc(sizeof(struct xfs_mount_args), GFP_KERNEL);
85 if (!args)
86 return NULL;
87
78 args->logbufs = args->logbufsize = -1; 88 args->logbufs = args->logbufsize = -1;
79 strncpy(args->fsname, sb->s_id, MAXNAMELEN); 89 strncpy(args->fsname, sb->s_id, MAXNAMELEN);
80 90
@@ -138,6 +148,23 @@ xfs_args_allocate(
138#define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */ 148#define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */
139#define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */ 149#define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */
140 150
151/*
152 * Table driven mount option parser.
153 *
154 * Currently only used for remount, but it will be used for mount
155 * in the future, too.
156 */
157enum {
158 Opt_barrier, Opt_nobarrier, Opt_err
159};
160
161static match_table_t tokens = {
162 {Opt_barrier, "barrier"},
163 {Opt_nobarrier, "nobarrier"},
164 {Opt_err, NULL}
165};
166
167
141STATIC unsigned long 168STATIC unsigned long
142suffix_strtoul(char *s, char **endp, unsigned int base) 169suffix_strtoul(char *s, char **endp, unsigned int base)
143{ 170{
@@ -314,6 +341,7 @@ xfs_parseargs(
314 args->flags |= XFSMNT_ATTR2; 341 args->flags |= XFSMNT_ATTR2;
315 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) { 342 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
316 args->flags &= ~XFSMNT_ATTR2; 343 args->flags &= ~XFSMNT_ATTR2;
344 args->flags |= XFSMNT_NOATTR2;
317 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) { 345 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
318 args->flags2 |= XFSMNT2_FILESTREAMS; 346 args->flags2 |= XFSMNT2_FILESTREAMS;
319 } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) { 347 } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
@@ -564,7 +592,10 @@ xfs_set_inodeops(
564 inode->i_mapping->a_ops = &xfs_address_space_operations; 592 inode->i_mapping->a_ops = &xfs_address_space_operations;
565 break; 593 break;
566 case S_IFDIR: 594 case S_IFDIR:
567 inode->i_op = &xfs_dir_inode_operations; 595 if (xfs_sb_version_hasasciici(&XFS_M(inode->i_sb)->m_sb))
596 inode->i_op = &xfs_dir_ci_inode_operations;
597 else
598 inode->i_op = &xfs_dir_inode_operations;
568 inode->i_fop = &xfs_dir_file_operations; 599 inode->i_fop = &xfs_dir_file_operations;
569 break; 600 break;
570 case S_IFLNK: 601 case S_IFLNK:
@@ -733,14 +764,6 @@ xfs_mountfs_check_barriers(xfs_mount_t *mp)
733 return; 764 return;
734 } 765 }
735 766
736 if (mp->m_ddev_targp->bt_bdev->bd_disk->queue->ordered ==
737 QUEUE_ORDERED_NONE) {
738 xfs_fs_cmn_err(CE_NOTE, mp,
739 "Disabling barriers, not supported by the underlying device");
740 mp->m_flags &= ~XFS_MOUNT_BARRIER;
741 return;
742 }
743
744 if (xfs_readonly_buftarg(mp->m_ddev_targp)) { 767 if (xfs_readonly_buftarg(mp->m_ddev_targp)) {
745 xfs_fs_cmn_err(CE_NOTE, mp, 768 xfs_fs_cmn_err(CE_NOTE, mp,
746 "Disabling barriers, underlying device is readonly"); 769 "Disabling barriers, underlying device is readonly");
@@ -764,6 +787,139 @@ xfs_blkdev_issue_flush(
764 blkdev_issue_flush(buftarg->bt_bdev, NULL); 787 blkdev_issue_flush(buftarg->bt_bdev, NULL);
765} 788}
766 789
790STATIC void
791xfs_close_devices(
792 struct xfs_mount *mp)
793{
794 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
795 struct block_device *logdev = mp->m_logdev_targp->bt_bdev;
796 xfs_free_buftarg(mp->m_logdev_targp);
797 xfs_blkdev_put(logdev);
798 }
799 if (mp->m_rtdev_targp) {
800 struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;
801 xfs_free_buftarg(mp->m_rtdev_targp);
802 xfs_blkdev_put(rtdev);
803 }
804 xfs_free_buftarg(mp->m_ddev_targp);
805}
806
807/*
808 * The file system configurations are:
809 * (1) device (partition) with data and internal log
810 * (2) logical volume with data and log subvolumes.
811 * (3) logical volume with data, log, and realtime subvolumes.
812 *
813 * We only have to handle opening the log and realtime volumes here if
814 * they are present. The data subvolume has already been opened by
815 * get_sb_bdev() and is stored in sb->s_bdev.
816 */
817STATIC int
818xfs_open_devices(
819 struct xfs_mount *mp,
820 struct xfs_mount_args *args)
821{
822 struct block_device *ddev = mp->m_super->s_bdev;
823 struct block_device *logdev = NULL, *rtdev = NULL;
824 int error;
825
826 /*
827 * Open real time and log devices - order is important.
828 */
829 if (args->logname[0]) {
830 error = xfs_blkdev_get(mp, args->logname, &logdev);
831 if (error)
832 goto out;
833 }
834
835 if (args->rtname[0]) {
836 error = xfs_blkdev_get(mp, args->rtname, &rtdev);
837 if (error)
838 goto out_close_logdev;
839
840 if (rtdev == ddev || rtdev == logdev) {
841 cmn_err(CE_WARN,
842 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
843 error = EINVAL;
844 goto out_close_rtdev;
845 }
846 }
847
848 /*
849 * Setup xfs_mount buffer target pointers
850 */
851 error = ENOMEM;
852 mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
853 if (!mp->m_ddev_targp)
854 goto out_close_rtdev;
855
856 if (rtdev) {
857 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
858 if (!mp->m_rtdev_targp)
859 goto out_free_ddev_targ;
860 }
861
862 if (logdev && logdev != ddev) {
863 mp->m_logdev_targp = xfs_alloc_buftarg(logdev, 1);
864 if (!mp->m_logdev_targp)
865 goto out_free_rtdev_targ;
866 } else {
867 mp->m_logdev_targp = mp->m_ddev_targp;
868 }
869
870 return 0;
871
872 out_free_rtdev_targ:
873 if (mp->m_rtdev_targp)
874 xfs_free_buftarg(mp->m_rtdev_targp);
875 out_free_ddev_targ:
876 xfs_free_buftarg(mp->m_ddev_targp);
877 out_close_rtdev:
878 if (rtdev)
879 xfs_blkdev_put(rtdev);
880 out_close_logdev:
881 if (logdev && logdev != ddev)
882 xfs_blkdev_put(logdev);
883 out:
884 return error;
885}
886
887/*
888 * Setup xfs_mount buffer target pointers based on superblock
889 */
890STATIC int
891xfs_setup_devices(
892 struct xfs_mount *mp)
893{
894 int error;
895
896 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
897 mp->m_sb.sb_sectsize);
898 if (error)
899 return error;
900
901 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
902 unsigned int log_sector_size = BBSIZE;
903
904 if (xfs_sb_version_hassector(&mp->m_sb))
905 log_sector_size = mp->m_sb.sb_logsectsize;
906 error = xfs_setsize_buftarg(mp->m_logdev_targp,
907 mp->m_sb.sb_blocksize,
908 log_sector_size);
909 if (error)
910 return error;
911 }
912 if (mp->m_rtdev_targp) {
913 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
914 mp->m_sb.sb_blocksize,
915 mp->m_sb.sb_sectsize);
916 if (error)
917 return error;
918 }
919
920 return 0;
921}
922
767/* 923/*
768 * XFS AIL push thread support 924 * XFS AIL push thread support
769 */ 925 */
@@ -848,42 +1004,6 @@ xfs_fs_inode_init_once(
848 inode_init_once(vn_to_inode((bhv_vnode_t *)vnode)); 1004 inode_init_once(vn_to_inode((bhv_vnode_t *)vnode));
849} 1005}
850 1006
851STATIC int __init
852xfs_init_zones(void)
853{
854 xfs_vnode_zone = kmem_zone_init_flags(sizeof(bhv_vnode_t), "xfs_vnode",
855 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
856 KM_ZONE_SPREAD,
857 xfs_fs_inode_init_once);
858 if (!xfs_vnode_zone)
859 goto out;
860
861 xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
862 if (!xfs_ioend_zone)
863 goto out_destroy_vnode_zone;
864
865 xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
866 xfs_ioend_zone);
867 if (!xfs_ioend_pool)
868 goto out_free_ioend_zone;
869 return 0;
870
871 out_free_ioend_zone:
872 kmem_zone_destroy(xfs_ioend_zone);
873 out_destroy_vnode_zone:
874 kmem_zone_destroy(xfs_vnode_zone);
875 out:
876 return -ENOMEM;
877}
878
879STATIC void
880xfs_destroy_zones(void)
881{
882 mempool_destroy(xfs_ioend_pool);
883 kmem_zone_destroy(xfs_vnode_zone);
884 kmem_zone_destroy(xfs_ioend_zone);
885}
886
887/* 1007/*
888 * Attempt to flush the inode, this will actually fail 1008 * Attempt to flush the inode, this will actually fail
889 * if the inode is pinned, but we dirty the inode again 1009 * if the inode is pinned, but we dirty the inode again
@@ -1073,7 +1193,7 @@ xfssyncd(
1073 list_del(&work->w_list); 1193 list_del(&work->w_list);
1074 if (work == &mp->m_sync_work) 1194 if (work == &mp->m_sync_work)
1075 continue; 1195 continue;
1076 kmem_free(work, sizeof(struct bhv_vfs_sync_work)); 1196 kmem_free(work);
1077 } 1197 }
1078 } 1198 }
1079 1199
@@ -1085,14 +1205,63 @@ xfs_fs_put_super(
1085 struct super_block *sb) 1205 struct super_block *sb)
1086{ 1206{
1087 struct xfs_mount *mp = XFS_M(sb); 1207 struct xfs_mount *mp = XFS_M(sb);
1208 struct xfs_inode *rip = mp->m_rootip;
1209 int unmount_event_flags = 0;
1088 int error; 1210 int error;
1089 1211
1090 kthread_stop(mp->m_sync_task); 1212 kthread_stop(mp->m_sync_task);
1091 1213
1092 xfs_sync(mp, SYNC_ATTR | SYNC_DELWRI); 1214 xfs_sync(mp, SYNC_ATTR | SYNC_DELWRI);
1093 error = xfs_unmount(mp, 0, NULL); 1215
1094 if (error) 1216#ifdef HAVE_DMAPI
1095 printk("XFS: unmount got error=%d\n", error); 1217 if (mp->m_flags & XFS_MOUNT_DMAPI) {
1218 unmount_event_flags =
1219 (mp->m_dmevmask & (1 << DM_EVENT_UNMOUNT)) ?
1220 0 : DM_FLAGS_UNWANTED;
1221 /*
1222 * Ignore error from dmapi here, first unmount is not allowed
1223 * to fail anyway, and second we wouldn't want to fail a
1224 * unmount because of dmapi.
1225 */
1226 XFS_SEND_PREUNMOUNT(mp, rip, DM_RIGHT_NULL, rip, DM_RIGHT_NULL,
1227 NULL, NULL, 0, 0, unmount_event_flags);
1228 }
1229#endif
1230
1231 /*
1232 * Blow away any referenced inode in the filestreams cache.
1233 * This can and will cause log traffic as inodes go inactive
1234 * here.
1235 */
1236 xfs_filestream_unmount(mp);
1237
1238 XFS_bflush(mp->m_ddev_targp);
1239 error = xfs_unmount_flush(mp, 0);
1240 WARN_ON(error);
1241
1242 IRELE(rip);
1243
1244 /*
1245 * If we're forcing a shutdown, typically because of a media error,
1246 * we want to make sure we invalidate dirty pages that belong to
1247 * referenced vnodes as well.
1248 */
1249 if (XFS_FORCED_SHUTDOWN(mp)) {
1250 error = xfs_sync(mp, SYNC_WAIT | SYNC_CLOSE);
1251 ASSERT(error != EFSCORRUPTED);
1252 }
1253
1254 if (mp->m_flags & XFS_MOUNT_DMAPI) {
1255 XFS_SEND_UNMOUNT(mp, rip, DM_RIGHT_NULL, 0, 0,
1256 unmount_event_flags);
1257 }
1258
1259 xfs_unmountfs(mp);
1260 xfs_icsb_destroy_counters(mp);
1261 xfs_close_devices(mp);
1262 xfs_qmops_put(mp);
1263 xfs_dmops_put(mp);
1264 kfree(mp);
1096} 1265}
1097 1266
1098STATIC void 1267STATIC void
@@ -1215,14 +1384,54 @@ xfs_fs_remount(
1215 char *options) 1384 char *options)
1216{ 1385{
1217 struct xfs_mount *mp = XFS_M(sb); 1386 struct xfs_mount *mp = XFS_M(sb);
1218 struct xfs_mount_args *args = xfs_args_allocate(sb, 0); 1387 substring_t args[MAX_OPT_ARGS];
1219 int error; 1388 char *p;
1220 1389
1221 error = xfs_parseargs(mp, options, args, 1); 1390 while ((p = strsep(&options, ",")) != NULL) {
1222 if (!error) 1391 int token;
1223 error = xfs_mntupdate(mp, flags, args); 1392
1224 kmem_free(args, sizeof(*args)); 1393 if (!*p)
1225 return -error; 1394 continue;
1395
1396 token = match_token(p, tokens, args);
1397 switch (token) {
1398 case Opt_barrier:
1399 mp->m_flags |= XFS_MOUNT_BARRIER;
1400
1401 /*
1402 * Test if barriers are actually working if we can,
1403 * else delay this check until the filesystem is
1404 * marked writeable.
1405 */
1406 if (!(mp->m_flags & XFS_MOUNT_RDONLY))
1407 xfs_mountfs_check_barriers(mp);
1408 break;
1409 case Opt_nobarrier:
1410 mp->m_flags &= ~XFS_MOUNT_BARRIER;
1411 break;
1412 default:
1413 printk(KERN_INFO
1414 "XFS: mount option \"%s\" not supported for remount\n", p);
1415 return -EINVAL;
1416 }
1417 }
1418
1419 /* rw/ro -> rw */
1420 if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & MS_RDONLY)) {
1421 mp->m_flags &= ~XFS_MOUNT_RDONLY;
1422 if (mp->m_flags & XFS_MOUNT_BARRIER)
1423 xfs_mountfs_check_barriers(mp);
1424 }
1425
1426 /* rw -> ro */
1427 if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & MS_RDONLY)) {
1428 xfs_filestream_flush(mp);
1429 xfs_sync(mp, SYNC_DATA_QUIESCE);
1430 xfs_attr_quiesce(mp);
1431 mp->m_flags |= XFS_MOUNT_RDONLY;
1432 }
1433
1434 return 0;
1226} 1435}
1227 1436
1228/* 1437/*
@@ -1299,6 +1508,225 @@ xfs_fs_setxquota(
1299 Q_XSETPQLIM), id, (caddr_t)fdq); 1508 Q_XSETPQLIM), id, (caddr_t)fdq);
1300} 1509}
1301 1510
1511/*
1512 * This function fills in xfs_mount_t fields based on mount args.
1513 * Note: the superblock has _not_ yet been read in.
1514 */
1515STATIC int
1516xfs_start_flags(
1517 struct xfs_mount_args *ap,
1518 struct xfs_mount *mp)
1519{
1520 /* Values are in BBs */
1521 if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
1522 /*
1523 * At this point the superblock has not been read
1524 * in, therefore we do not know the block size.
1525 * Before the mount call ends we will convert
1526 * these to FSBs.
1527 */
1528 mp->m_dalign = ap->sunit;
1529 mp->m_swidth = ap->swidth;
1530 }
1531
1532 if (ap->logbufs != -1 &&
1533 ap->logbufs != 0 &&
1534 (ap->logbufs < XLOG_MIN_ICLOGS ||
1535 ap->logbufs > XLOG_MAX_ICLOGS)) {
1536 cmn_err(CE_WARN,
1537 "XFS: invalid logbufs value: %d [not %d-%d]",
1538 ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
1539 return XFS_ERROR(EINVAL);
1540 }
1541 mp->m_logbufs = ap->logbufs;
1542 if (ap->logbufsize != -1 &&
1543 ap->logbufsize != 0 &&
1544 (ap->logbufsize < XLOG_MIN_RECORD_BSIZE ||
1545 ap->logbufsize > XLOG_MAX_RECORD_BSIZE ||
1546 !is_power_of_2(ap->logbufsize))) {
1547 cmn_err(CE_WARN,
1548 "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
1549 ap->logbufsize);
1550 return XFS_ERROR(EINVAL);
1551 }
1552 mp->m_logbsize = ap->logbufsize;
1553 mp->m_fsname_len = strlen(ap->fsname) + 1;
1554 mp->m_fsname = kmem_alloc(mp->m_fsname_len, KM_SLEEP);
1555 strcpy(mp->m_fsname, ap->fsname);
1556 if (ap->rtname[0]) {
1557 mp->m_rtname = kmem_alloc(strlen(ap->rtname) + 1, KM_SLEEP);
1558 strcpy(mp->m_rtname, ap->rtname);
1559 }
1560 if (ap->logname[0]) {
1561 mp->m_logname = kmem_alloc(strlen(ap->logname) + 1, KM_SLEEP);
1562 strcpy(mp->m_logname, ap->logname);
1563 }
1564
1565 if (ap->flags & XFSMNT_WSYNC)
1566 mp->m_flags |= XFS_MOUNT_WSYNC;
1567#if XFS_BIG_INUMS
1568 if (ap->flags & XFSMNT_INO64) {
1569 mp->m_flags |= XFS_MOUNT_INO64;
1570 mp->m_inoadd = XFS_INO64_OFFSET;
1571 }
1572#endif
1573 if (ap->flags & XFSMNT_RETERR)
1574 mp->m_flags |= XFS_MOUNT_RETERR;
1575 if (ap->flags & XFSMNT_NOALIGN)
1576 mp->m_flags |= XFS_MOUNT_NOALIGN;
1577 if (ap->flags & XFSMNT_SWALLOC)
1578 mp->m_flags |= XFS_MOUNT_SWALLOC;
1579 if (ap->flags & XFSMNT_OSYNCISOSYNC)
1580 mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
1581 if (ap->flags & XFSMNT_32BITINODES)
1582 mp->m_flags |= XFS_MOUNT_32BITINODES;
1583
1584 if (ap->flags & XFSMNT_IOSIZE) {
1585 if (ap->iosizelog > XFS_MAX_IO_LOG ||
1586 ap->iosizelog < XFS_MIN_IO_LOG) {
1587 cmn_err(CE_WARN,
1588 "XFS: invalid log iosize: %d [not %d-%d]",
1589 ap->iosizelog, XFS_MIN_IO_LOG,
1590 XFS_MAX_IO_LOG);
1591 return XFS_ERROR(EINVAL);
1592 }
1593
1594 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
1595 mp->m_readio_log = mp->m_writeio_log = ap->iosizelog;
1596 }
1597
1598 if (ap->flags & XFSMNT_IKEEP)
1599 mp->m_flags |= XFS_MOUNT_IKEEP;
1600 if (ap->flags & XFSMNT_DIRSYNC)
1601 mp->m_flags |= XFS_MOUNT_DIRSYNC;
1602 if (ap->flags & XFSMNT_ATTR2)
1603 mp->m_flags |= XFS_MOUNT_ATTR2;
1604 if (ap->flags & XFSMNT_NOATTR2)
1605 mp->m_flags |= XFS_MOUNT_NOATTR2;
1606
1607 if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
1608 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
1609
1610 /*
1611 * no recovery flag requires a read-only mount
1612 */
1613 if (ap->flags & XFSMNT_NORECOVERY) {
1614 if (!(mp->m_flags & XFS_MOUNT_RDONLY)) {
1615 cmn_err(CE_WARN,
1616 "XFS: tried to mount a FS read-write without recovery!");
1617 return XFS_ERROR(EINVAL);
1618 }
1619 mp->m_flags |= XFS_MOUNT_NORECOVERY;
1620 }
1621
1622 if (ap->flags & XFSMNT_NOUUID)
1623 mp->m_flags |= XFS_MOUNT_NOUUID;
1624 if (ap->flags & XFSMNT_BARRIER)
1625 mp->m_flags |= XFS_MOUNT_BARRIER;
1626 else
1627 mp->m_flags &= ~XFS_MOUNT_BARRIER;
1628
1629 if (ap->flags2 & XFSMNT2_FILESTREAMS)
1630 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
1631
1632 if (ap->flags & XFSMNT_DMAPI)
1633 mp->m_flags |= XFS_MOUNT_DMAPI;
1634 return 0;
1635}
1636
1637/*
1638 * This function fills in xfs_mount_t fields based on mount args.
1639 * Note: the superblock _has_ now been read in.
1640 */
1641STATIC int
1642xfs_finish_flags(
1643 struct xfs_mount_args *ap,
1644 struct xfs_mount *mp)
1645{
1646 int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
1647
1648 /* Fail a mount where the logbuf is smaller then the log stripe */
1649 if (xfs_sb_version_haslogv2(&mp->m_sb)) {
1650 if ((ap->logbufsize <= 0) &&
1651 (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
1652 mp->m_logbsize = mp->m_sb.sb_logsunit;
1653 } else if (ap->logbufsize > 0 &&
1654 ap->logbufsize < mp->m_sb.sb_logsunit) {
1655 cmn_err(CE_WARN,
1656 "XFS: logbuf size must be greater than or equal to log stripe size");
1657 return XFS_ERROR(EINVAL);
1658 }
1659 } else {
1660 /* Fail a mount if the logbuf is larger than 32K */
1661 if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) {
1662 cmn_err(CE_WARN,
1663 "XFS: logbuf size for version 1 logs must be 16K or 32K");
1664 return XFS_ERROR(EINVAL);
1665 }
1666 }
1667
1668 /*
1669 * mkfs'ed attr2 will turn on attr2 mount unless explicitly
1670 * told by noattr2 to turn it off
1671 */
1672 if (xfs_sb_version_hasattr2(&mp->m_sb) &&
1673 !(ap->flags & XFSMNT_NOATTR2))
1674 mp->m_flags |= XFS_MOUNT_ATTR2;
1675
1676 /*
1677 * prohibit r/w mounts of read-only filesystems
1678 */
1679 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
1680 cmn_err(CE_WARN,
1681 "XFS: cannot mount a read-only filesystem as read-write");
1682 return XFS_ERROR(EROFS);
1683 }
1684
1685 /*
1686 * check for shared mount.
1687 */
1688 if (ap->flags & XFSMNT_SHARED) {
1689 if (!xfs_sb_version_hasshared(&mp->m_sb))
1690 return XFS_ERROR(EINVAL);
1691
1692 /*
1693 * For IRIX 6.5, shared mounts must have the shared
1694 * version bit set, have the persistent readonly
1695 * field set, must be version 0 and can only be mounted
1696 * read-only.
1697 */
1698 if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
1699 (mp->m_sb.sb_shared_vn != 0))
1700 return XFS_ERROR(EINVAL);
1701
1702 mp->m_flags |= XFS_MOUNT_SHARED;
1703
1704 /*
1705 * Shared XFS V0 can't deal with DMI. Return EINVAL.
1706 */
1707 if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI))
1708 return XFS_ERROR(EINVAL);
1709 }
1710
1711 if (ap->flags & XFSMNT_UQUOTA) {
1712 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
1713 if (ap->flags & XFSMNT_UQUOTAENF)
1714 mp->m_qflags |= XFS_UQUOTA_ENFD;
1715 }
1716
1717 if (ap->flags & XFSMNT_GQUOTA) {
1718 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
1719 if (ap->flags & XFSMNT_GQUOTAENF)
1720 mp->m_qflags |= XFS_OQUOTA_ENFD;
1721 } else if (ap->flags & XFSMNT_PQUOTA) {
1722 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
1723 if (ap->flags & XFSMNT_PQUOTAENF)
1724 mp->m_qflags |= XFS_OQUOTA_ENFD;
1725 }
1726
1727 return 0;
1728}
1729
1302STATIC int 1730STATIC int
1303xfs_fs_fill_super( 1731xfs_fs_fill_super(
1304 struct super_block *sb, 1732 struct super_block *sb,
@@ -1307,11 +1735,21 @@ xfs_fs_fill_super(
1307{ 1735{
1308 struct inode *root; 1736 struct inode *root;
1309 struct xfs_mount *mp = NULL; 1737 struct xfs_mount *mp = NULL;
1310 struct xfs_mount_args *args = xfs_args_allocate(sb, silent); 1738 struct xfs_mount_args *args;
1311 int error; 1739 int flags = 0, error = ENOMEM;
1740
1741 args = xfs_args_allocate(sb, silent);
1742 if (!args)
1743 return -ENOMEM;
1312 1744
1313 mp = xfs_mount_init(); 1745 mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
1746 if (!mp)
1747 goto out_free_args;
1314 1748
1749 spin_lock_init(&mp->m_sb_lock);
1750 mutex_init(&mp->m_ilock);
1751 mutex_init(&mp->m_growlock);
1752 atomic_set(&mp->m_active_trans, 0);
1315 INIT_LIST_HEAD(&mp->m_sync_list); 1753 INIT_LIST_HEAD(&mp->m_sync_list);
1316 spin_lock_init(&mp->m_sync_lock); 1754 spin_lock_init(&mp->m_sync_lock);
1317 init_waitqueue_head(&mp->m_wait_single_sync_task); 1755 init_waitqueue_head(&mp->m_wait_single_sync_task);
@@ -1324,16 +1762,60 @@ xfs_fs_fill_super(
1324 1762
1325 error = xfs_parseargs(mp, (char *)data, args, 0); 1763 error = xfs_parseargs(mp, (char *)data, args, 0);
1326 if (error) 1764 if (error)
1327 goto fail_vfsop; 1765 goto out_free_mp;
1328 1766
1329 sb_min_blocksize(sb, BBSIZE); 1767 sb_min_blocksize(sb, BBSIZE);
1768 sb->s_xattr = xfs_xattr_handlers;
1330 sb->s_export_op = &xfs_export_operations; 1769 sb->s_export_op = &xfs_export_operations;
1331 sb->s_qcop = &xfs_quotactl_operations; 1770 sb->s_qcop = &xfs_quotactl_operations;
1332 sb->s_op = &xfs_super_operations; 1771 sb->s_op = &xfs_super_operations;
1333 1772
1334 error = xfs_mount(mp, args, NULL); 1773 error = xfs_dmops_get(mp, args);
1335 if (error) 1774 if (error)
1336 goto fail_vfsop; 1775 goto out_free_mp;
1776 error = xfs_qmops_get(mp, args);
1777 if (error)
1778 goto out_put_dmops;
1779
1780 if (args->flags & XFSMNT_QUIET)
1781 flags |= XFS_MFSI_QUIET;
1782
1783 error = xfs_open_devices(mp, args);
1784 if (error)
1785 goto out_put_qmops;
1786
1787 if (xfs_icsb_init_counters(mp))
1788 mp->m_flags |= XFS_MOUNT_NO_PERCPU_SB;
1789
1790 /*
1791 * Setup flags based on mount(2) options and then the superblock
1792 */
1793 error = xfs_start_flags(args, mp);
1794 if (error)
1795 goto out_destroy_counters;
1796 error = xfs_readsb(mp, flags);
1797 if (error)
1798 goto out_destroy_counters;
1799 error = xfs_finish_flags(args, mp);
1800 if (error)
1801 goto out_free_sb;
1802
1803 error = xfs_setup_devices(mp);
1804 if (error)
1805 goto out_free_sb;
1806
1807 if (mp->m_flags & XFS_MOUNT_BARRIER)
1808 xfs_mountfs_check_barriers(mp);
1809
1810 error = xfs_filestream_mount(mp);
1811 if (error)
1812 goto out_free_sb;
1813
1814 error = xfs_mountfs(mp, flags);
1815 if (error)
1816 goto out_filestream_unmount;
1817
1818 XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname);
1337 1819
1338 sb->s_dirt = 1; 1820 sb->s_dirt = 1;
1339 sb->s_magic = XFS_SB_MAGIC; 1821 sb->s_magic = XFS_SB_MAGIC;
@@ -1368,10 +1850,27 @@ xfs_fs_fill_super(
1368 1850
1369 xfs_itrace_exit(XFS_I(sb->s_root->d_inode)); 1851 xfs_itrace_exit(XFS_I(sb->s_root->d_inode));
1370 1852
1371 kmem_free(args, sizeof(*args)); 1853 kfree(args);
1372 return 0; 1854 return 0;
1373 1855
1374fail_vnrele: 1856 out_filestream_unmount:
1857 xfs_filestream_unmount(mp);
1858 out_free_sb:
1859 xfs_freesb(mp);
1860 out_destroy_counters:
1861 xfs_icsb_destroy_counters(mp);
1862 xfs_close_devices(mp);
1863 out_put_qmops:
1864 xfs_qmops_put(mp);
1865 out_put_dmops:
1866 xfs_dmops_put(mp);
1867 out_free_mp:
1868 kfree(mp);
1869 out_free_args:
1870 kfree(args);
1871 return -error;
1872
1873 fail_vnrele:
1375 if (sb->s_root) { 1874 if (sb->s_root) {
1376 dput(sb->s_root); 1875 dput(sb->s_root);
1377 sb->s_root = NULL; 1876 sb->s_root = NULL;
@@ -1379,12 +1878,22 @@ fail_vnrele:
1379 iput(root); 1878 iput(root);
1380 } 1879 }
1381 1880
1382fail_unmount: 1881 fail_unmount:
1383 xfs_unmount(mp, 0, NULL); 1882 /*
1883 * Blow away any referenced inode in the filestreams cache.
1884 * This can and will cause log traffic as inodes go inactive
1885 * here.
1886 */
1887 xfs_filestream_unmount(mp);
1384 1888
1385fail_vfsop: 1889 XFS_bflush(mp->m_ddev_targp);
1386 kmem_free(args, sizeof(*args)); 1890 error = xfs_unmount_flush(mp, 0);
1387 return -error; 1891 WARN_ON(error);
1892
1893 IRELE(mp->m_rootip);
1894
1895 xfs_unmountfs(mp);
1896 goto out_destroy_counters;
1388} 1897}
1389 1898
1390STATIC int 1899STATIC int
@@ -1429,9 +1938,235 @@ static struct file_system_type xfs_fs_type = {
1429 .fs_flags = FS_REQUIRES_DEV, 1938 .fs_flags = FS_REQUIRES_DEV,
1430}; 1939};
1431 1940
1941STATIC int __init
1942xfs_alloc_trace_bufs(void)
1943{
1944#ifdef XFS_ALLOC_TRACE
1945 xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_MAYFAIL);
1946 if (!xfs_alloc_trace_buf)
1947 goto out;
1948#endif
1949#ifdef XFS_BMAP_TRACE
1950 xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_MAYFAIL);
1951 if (!xfs_bmap_trace_buf)
1952 goto out_free_alloc_trace;
1953#endif
1954#ifdef XFS_BMBT_TRACE
1955 xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_MAYFAIL);
1956 if (!xfs_bmbt_trace_buf)
1957 goto out_free_bmap_trace;
1958#endif
1959#ifdef XFS_ATTR_TRACE
1960 xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_MAYFAIL);
1961 if (!xfs_attr_trace_buf)
1962 goto out_free_bmbt_trace;
1963#endif
1964#ifdef XFS_DIR2_TRACE
1965 xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_MAYFAIL);
1966 if (!xfs_dir2_trace_buf)
1967 goto out_free_attr_trace;
1968#endif
1969
1970 return 0;
1971
1972#ifdef XFS_DIR2_TRACE
1973 out_free_attr_trace:
1974#endif
1975#ifdef XFS_ATTR_TRACE
1976 ktrace_free(xfs_attr_trace_buf);
1977 out_free_bmbt_trace:
1978#endif
1979#ifdef XFS_BMBT_TRACE
1980 ktrace_free(xfs_bmbt_trace_buf);
1981 out_free_bmap_trace:
1982#endif
1983#ifdef XFS_BMAP_TRACE
1984 ktrace_free(xfs_bmap_trace_buf);
1985 out_free_alloc_trace:
1986#endif
1987#ifdef XFS_ALLOC_TRACE
1988 ktrace_free(xfs_alloc_trace_buf);
1989 out:
1990#endif
1991 return -ENOMEM;
1992}
1993
1994STATIC void
1995xfs_free_trace_bufs(void)
1996{
1997#ifdef XFS_DIR2_TRACE
1998 ktrace_free(xfs_dir2_trace_buf);
1999#endif
2000#ifdef XFS_ATTR_TRACE
2001 ktrace_free(xfs_attr_trace_buf);
2002#endif
2003#ifdef XFS_BMBT_TRACE
2004 ktrace_free(xfs_bmbt_trace_buf);
2005#endif
2006#ifdef XFS_BMAP_TRACE
2007 ktrace_free(xfs_bmap_trace_buf);
2008#endif
2009#ifdef XFS_ALLOC_TRACE
2010 ktrace_free(xfs_alloc_trace_buf);
2011#endif
2012}
1432 2013
1433STATIC int __init 2014STATIC int __init
1434init_xfs_fs( void ) 2015xfs_init_zones(void)
2016{
2017 xfs_vnode_zone = kmem_zone_init_flags(sizeof(bhv_vnode_t), "xfs_vnode",
2018 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
2019 KM_ZONE_SPREAD,
2020 xfs_fs_inode_init_once);
2021 if (!xfs_vnode_zone)
2022 goto out;
2023
2024 xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
2025 if (!xfs_ioend_zone)
2026 goto out_destroy_vnode_zone;
2027
2028 xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
2029 xfs_ioend_zone);
2030 if (!xfs_ioend_pool)
2031 goto out_destroy_ioend_zone;
2032
2033 xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
2034 "xfs_log_ticket");
2035 if (!xfs_log_ticket_zone)
2036 goto out_destroy_ioend_pool;
2037
2038 xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
2039 "xfs_bmap_free_item");
2040 if (!xfs_bmap_free_item_zone)
2041 goto out_destroy_log_ticket_zone;
2042 xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
2043 "xfs_btree_cur");
2044 if (!xfs_btree_cur_zone)
2045 goto out_destroy_bmap_free_item_zone;
2046
2047 xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
2048 "xfs_da_state");
2049 if (!xfs_da_state_zone)
2050 goto out_destroy_btree_cur_zone;
2051
2052 xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
2053 if (!xfs_dabuf_zone)
2054 goto out_destroy_da_state_zone;
2055
2056 xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
2057 if (!xfs_ifork_zone)
2058 goto out_destroy_dabuf_zone;
2059
2060 xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
2061 if (!xfs_trans_zone)
2062 goto out_destroy_ifork_zone;
2063
2064 /*
2065 * The size of the zone allocated buf log item is the maximum
2066 * size possible under XFS. This wastes a little bit of memory,
2067 * but it is much faster.
2068 */
2069 xfs_buf_item_zone = kmem_zone_init((sizeof(xfs_buf_log_item_t) +
2070 (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) /
2071 NBWORD) * sizeof(int))), "xfs_buf_item");
2072 if (!xfs_buf_item_zone)
2073 goto out_destroy_trans_zone;
2074
2075 xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
2076 ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
2077 sizeof(xfs_extent_t))), "xfs_efd_item");
2078 if (!xfs_efd_zone)
2079 goto out_destroy_buf_item_zone;
2080
2081 xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
2082 ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
2083 sizeof(xfs_extent_t))), "xfs_efi_item");
2084 if (!xfs_efi_zone)
2085 goto out_destroy_efd_zone;
2086
2087 xfs_inode_zone =
2088 kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
2089 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
2090 KM_ZONE_SPREAD, NULL);
2091 if (!xfs_inode_zone)
2092 goto out_destroy_efi_zone;
2093
2094 xfs_ili_zone =
2095 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
2096 KM_ZONE_SPREAD, NULL);
2097 if (!xfs_ili_zone)
2098 goto out_destroy_inode_zone;
2099
2100#ifdef CONFIG_XFS_POSIX_ACL
2101 xfs_acl_zone = kmem_zone_init(sizeof(xfs_acl_t), "xfs_acl");
2102 if (!xfs_acl_zone)
2103 goto out_destroy_ili_zone;
2104#endif
2105
2106 return 0;
2107
2108#ifdef CONFIG_XFS_POSIX_ACL
2109 out_destroy_ili_zone:
2110#endif
2111 kmem_zone_destroy(xfs_ili_zone);
2112 out_destroy_inode_zone:
2113 kmem_zone_destroy(xfs_inode_zone);
2114 out_destroy_efi_zone:
2115 kmem_zone_destroy(xfs_efi_zone);
2116 out_destroy_efd_zone:
2117 kmem_zone_destroy(xfs_efd_zone);
2118 out_destroy_buf_item_zone:
2119 kmem_zone_destroy(xfs_buf_item_zone);
2120 out_destroy_trans_zone:
2121 kmem_zone_destroy(xfs_trans_zone);
2122 out_destroy_ifork_zone:
2123 kmem_zone_destroy(xfs_ifork_zone);
2124 out_destroy_dabuf_zone:
2125 kmem_zone_destroy(xfs_dabuf_zone);
2126 out_destroy_da_state_zone:
2127 kmem_zone_destroy(xfs_da_state_zone);
2128 out_destroy_btree_cur_zone:
2129 kmem_zone_destroy(xfs_btree_cur_zone);
2130 out_destroy_bmap_free_item_zone:
2131 kmem_zone_destroy(xfs_bmap_free_item_zone);
2132 out_destroy_log_ticket_zone:
2133 kmem_zone_destroy(xfs_log_ticket_zone);
2134 out_destroy_ioend_pool:
2135 mempool_destroy(xfs_ioend_pool);
2136 out_destroy_ioend_zone:
2137 kmem_zone_destroy(xfs_ioend_zone);
2138 out_destroy_vnode_zone:
2139 kmem_zone_destroy(xfs_vnode_zone);
2140 out:
2141 return -ENOMEM;
2142}
2143
2144STATIC void
2145xfs_destroy_zones(void)
2146{
2147#ifdef CONFIG_XFS_POSIX_ACL
2148 kmem_zone_destroy(xfs_acl_zone);
2149#endif
2150 kmem_zone_destroy(xfs_ili_zone);
2151 kmem_zone_destroy(xfs_inode_zone);
2152 kmem_zone_destroy(xfs_efi_zone);
2153 kmem_zone_destroy(xfs_efd_zone);
2154 kmem_zone_destroy(xfs_buf_item_zone);
2155 kmem_zone_destroy(xfs_trans_zone);
2156 kmem_zone_destroy(xfs_ifork_zone);
2157 kmem_zone_destroy(xfs_dabuf_zone);
2158 kmem_zone_destroy(xfs_da_state_zone);
2159 kmem_zone_destroy(xfs_btree_cur_zone);
2160 kmem_zone_destroy(xfs_bmap_free_item_zone);
2161 kmem_zone_destroy(xfs_log_ticket_zone);
2162 mempool_destroy(xfs_ioend_pool);
2163 kmem_zone_destroy(xfs_ioend_zone);
2164 kmem_zone_destroy(xfs_vnode_zone);
2165
2166}
2167
2168STATIC int __init
2169init_xfs_fs(void)
1435{ 2170{
1436 int error; 2171 int error;
1437 static char message[] __initdata = KERN_INFO \ 2172 static char message[] __initdata = KERN_INFO \
@@ -1440,42 +2175,73 @@ init_xfs_fs( void )
1440 printk(message); 2175 printk(message);
1441 2176
1442 ktrace_init(64); 2177 ktrace_init(64);
2178 vn_init();
2179 xfs_dir_startup();
1443 2180
1444 error = xfs_init_zones(); 2181 error = xfs_init_zones();
1445 if (error < 0) 2182 if (error)
1446 goto undo_zones; 2183 goto out;
2184
2185 error = xfs_alloc_trace_bufs();
2186 if (error)
2187 goto out_destroy_zones;
2188
2189 error = xfs_mru_cache_init();
2190 if (error)
2191 goto out_free_trace_buffers;
2192
2193 error = xfs_filestream_init();
2194 if (error)
2195 goto out_mru_cache_uninit;
1447 2196
1448 error = xfs_buf_init(); 2197 error = xfs_buf_init();
1449 if (error < 0) 2198 if (error)
1450 goto undo_buffers; 2199 goto out_filestream_uninit;
2200
2201 error = xfs_init_procfs();
2202 if (error)
2203 goto out_buf_terminate;
2204
2205 error = xfs_sysctl_register();
2206 if (error)
2207 goto out_cleanup_procfs;
1451 2208
1452 vn_init();
1453 xfs_init();
1454 uuid_init();
1455 vfs_initquota(); 2209 vfs_initquota();
1456 2210
1457 error = register_filesystem(&xfs_fs_type); 2211 error = register_filesystem(&xfs_fs_type);
1458 if (error) 2212 if (error)
1459 goto undo_register; 2213 goto out_sysctl_unregister;
1460 return 0; 2214 return 0;
1461 2215
1462undo_register: 2216 out_sysctl_unregister:
2217 xfs_sysctl_unregister();
2218 out_cleanup_procfs:
2219 xfs_cleanup_procfs();
2220 out_buf_terminate:
1463 xfs_buf_terminate(); 2221 xfs_buf_terminate();
1464 2222 out_filestream_uninit:
1465undo_buffers: 2223 xfs_filestream_uninit();
2224 out_mru_cache_uninit:
2225 xfs_mru_cache_uninit();
2226 out_free_trace_buffers:
2227 xfs_free_trace_bufs();
2228 out_destroy_zones:
1466 xfs_destroy_zones(); 2229 xfs_destroy_zones();
1467 2230 out:
1468undo_zones:
1469 return error; 2231 return error;
1470} 2232}
1471 2233
1472STATIC void __exit 2234STATIC void __exit
1473exit_xfs_fs( void ) 2235exit_xfs_fs(void)
1474{ 2236{
1475 vfs_exitquota(); 2237 vfs_exitquota();
1476 unregister_filesystem(&xfs_fs_type); 2238 unregister_filesystem(&xfs_fs_type);
1477 xfs_cleanup(); 2239 xfs_sysctl_unregister();
2240 xfs_cleanup_procfs();
1478 xfs_buf_terminate(); 2241 xfs_buf_terminate();
2242 xfs_filestream_uninit();
2243 xfs_mru_cache_uninit();
2244 xfs_free_trace_bufs();
1479 xfs_destroy_zones(); 2245 xfs_destroy_zones();
1480 ktrace_uninit(); 2246 ktrace_uninit();
1481} 2247}
diff --git a/fs/xfs/linux-2.6/xfs_super.h b/fs/xfs/linux-2.6/xfs_super.h
index 3efb7c6d3303..b7d13da01bd6 100644
--- a/fs/xfs/linux-2.6/xfs_super.h
+++ b/fs/xfs/linux-2.6/xfs_super.h
@@ -107,12 +107,10 @@ extern void xfs_initialize_vnode(struct xfs_mount *mp, bhv_vnode_t *vp,
107extern void xfs_flush_inode(struct xfs_inode *); 107extern void xfs_flush_inode(struct xfs_inode *);
108extern void xfs_flush_device(struct xfs_inode *); 108extern void xfs_flush_device(struct xfs_inode *);
109 109
110extern int xfs_blkdev_get(struct xfs_mount *, const char *,
111 struct block_device **);
112extern void xfs_blkdev_put(struct block_device *);
113extern void xfs_blkdev_issue_flush(struct xfs_buftarg *); 110extern void xfs_blkdev_issue_flush(struct xfs_buftarg *);
114 111
115extern const struct export_operations xfs_export_operations; 112extern const struct export_operations xfs_export_operations;
113extern struct xattr_handler *xfs_xattr_handlers[];
116 114
117#define XFS_M(sb) ((struct xfs_mount *)((sb)->s_fs_info)) 115#define XFS_M(sb) ((struct xfs_mount *)((sb)->s_fs_info))
118 116
diff --git a/fs/xfs/linux-2.6/xfs_sysctl.c b/fs/xfs/linux-2.6/xfs_sysctl.c
index bb997d75c05c..7dacb5bbde3f 100644
--- a/fs/xfs/linux-2.6/xfs_sysctl.c
+++ b/fs/xfs/linux-2.6/xfs_sysctl.c
@@ -259,15 +259,17 @@ static ctl_table xfs_root_table[] = {
259 {} 259 {}
260}; 260};
261 261
262void 262int
263xfs_sysctl_register(void) 263xfs_sysctl_register(void)
264{ 264{
265 xfs_table_header = register_sysctl_table(xfs_root_table); 265 xfs_table_header = register_sysctl_table(xfs_root_table);
266 if (!xfs_table_header)
267 return -ENOMEM;
268 return 0;
266} 269}
267 270
268void 271void
269xfs_sysctl_unregister(void) 272xfs_sysctl_unregister(void)
270{ 273{
271 if (xfs_table_header) 274 unregister_sysctl_table(xfs_table_header);
272 unregister_sysctl_table(xfs_table_header);
273} 275}
diff --git a/fs/xfs/linux-2.6/xfs_sysctl.h b/fs/xfs/linux-2.6/xfs_sysctl.h
index 98b97e399d6f..4aadb8056c37 100644
--- a/fs/xfs/linux-2.6/xfs_sysctl.h
+++ b/fs/xfs/linux-2.6/xfs_sysctl.h
@@ -93,10 +93,10 @@ enum {
93extern xfs_param_t xfs_params; 93extern xfs_param_t xfs_params;
94 94
95#ifdef CONFIG_SYSCTL 95#ifdef CONFIG_SYSCTL
96extern void xfs_sysctl_register(void); 96extern int xfs_sysctl_register(void);
97extern void xfs_sysctl_unregister(void); 97extern void xfs_sysctl_unregister(void);
98#else 98#else
99# define xfs_sysctl_register() do { } while (0) 99# define xfs_sysctl_register() (0)
100# define xfs_sysctl_unregister() do { } while (0) 100# define xfs_sysctl_unregister() do { } while (0)
101#endif /* CONFIG_SYSCTL */ 101#endif /* CONFIG_SYSCTL */
102 102
diff --git a/fs/xfs/linux-2.6/xfs_vnode.c b/fs/xfs/linux-2.6/xfs_vnode.c
index bc7afe007338..25488b6d9881 100644
--- a/fs/xfs/linux-2.6/xfs_vnode.c
+++ b/fs/xfs/linux-2.6/xfs_vnode.c
@@ -82,56 +82,6 @@ vn_ioerror(
82 xfs_do_force_shutdown(ip->i_mount, SHUTDOWN_DEVICE_REQ, f, l); 82 xfs_do_force_shutdown(ip->i_mount, SHUTDOWN_DEVICE_REQ, f, l);
83} 83}
84 84
85/*
86 * Revalidate the Linux inode from the XFS inode.
87 * Note: i_size _not_ updated; we must hold the inode
88 * semaphore when doing that - callers responsibility.
89 */
90int
91vn_revalidate(
92 bhv_vnode_t *vp)
93{
94 struct inode *inode = vn_to_inode(vp);
95 struct xfs_inode *ip = XFS_I(inode);
96 struct xfs_mount *mp = ip->i_mount;
97 unsigned long xflags;
98
99 xfs_itrace_entry(ip);
100
101 if (XFS_FORCED_SHUTDOWN(mp))
102 return -EIO;
103
104 xfs_ilock(ip, XFS_ILOCK_SHARED);
105 inode->i_mode = ip->i_d.di_mode;
106 inode->i_uid = ip->i_d.di_uid;
107 inode->i_gid = ip->i_d.di_gid;
108 inode->i_mtime.tv_sec = ip->i_d.di_mtime.t_sec;
109 inode->i_mtime.tv_nsec = ip->i_d.di_mtime.t_nsec;
110 inode->i_ctime.tv_sec = ip->i_d.di_ctime.t_sec;
111 inode->i_ctime.tv_nsec = ip->i_d.di_ctime.t_nsec;
112
113 xflags = xfs_ip2xflags(ip);
114 if (xflags & XFS_XFLAG_IMMUTABLE)
115 inode->i_flags |= S_IMMUTABLE;
116 else
117 inode->i_flags &= ~S_IMMUTABLE;
118 if (xflags & XFS_XFLAG_APPEND)
119 inode->i_flags |= S_APPEND;
120 else
121 inode->i_flags &= ~S_APPEND;
122 if (xflags & XFS_XFLAG_SYNC)
123 inode->i_flags |= S_SYNC;
124 else
125 inode->i_flags &= ~S_SYNC;
126 if (xflags & XFS_XFLAG_NOATIME)
127 inode->i_flags |= S_NOATIME;
128 else
129 inode->i_flags &= ~S_NOATIME;
130 xfs_iunlock(ip, XFS_ILOCK_SHARED);
131
132 xfs_iflags_clear(ip, XFS_IMODIFIED);
133 return 0;
134}
135 85
136/* 86/*
137 * Add a reference to a referenced vnode. 87 * Add a reference to a referenced vnode.
diff --git a/fs/xfs/linux-2.6/xfs_vnode.h b/fs/xfs/linux-2.6/xfs_vnode.h
index 25eb2a9e8d9b..41ca2cec5d31 100644
--- a/fs/xfs/linux-2.6/xfs_vnode.h
+++ b/fs/xfs/linux-2.6/xfs_vnode.h
@@ -19,7 +19,6 @@
19#define __XFS_VNODE_H__ 19#define __XFS_VNODE_H__
20 20
21struct file; 21struct file;
22struct bhv_vattr;
23struct xfs_iomap; 22struct xfs_iomap;
24struct attrlist_cursor_kern; 23struct attrlist_cursor_kern;
25 24
@@ -66,87 +65,8 @@ static inline struct inode *vn_to_inode(bhv_vnode_t *vnode)
66 Prevent VM access to the pages until 65 Prevent VM access to the pages until
67 the operation completes. */ 66 the operation completes. */
68 67
69/*
70 * Vnode attributes. va_mask indicates those attributes the caller
71 * wants to set or extract.
72 */
73typedef struct bhv_vattr {
74 int va_mask; /* bit-mask of attributes present */
75 mode_t va_mode; /* file access mode and type */
76 xfs_nlink_t va_nlink; /* number of references to file */
77 uid_t va_uid; /* owner user id */
78 gid_t va_gid; /* owner group id */
79 xfs_ino_t va_nodeid; /* file id */
80 xfs_off_t va_size; /* file size in bytes */
81 u_long va_blocksize; /* blocksize preferred for i/o */
82 struct timespec va_atime; /* time of last access */
83 struct timespec va_mtime; /* time of last modification */
84 struct timespec va_ctime; /* time file changed */
85 u_int va_gen; /* generation number of file */
86 xfs_dev_t va_rdev; /* device the special file represents */
87 __int64_t va_nblocks; /* number of blocks allocated */
88 u_long va_xflags; /* random extended file flags */
89 u_long va_extsize; /* file extent size */
90 u_long va_nextents; /* number of extents in file */
91 u_long va_anextents; /* number of attr extents in file */
92 prid_t va_projid; /* project id */
93} bhv_vattr_t;
94
95/*
96 * setattr or getattr attributes
97 */
98#define XFS_AT_TYPE 0x00000001
99#define XFS_AT_MODE 0x00000002
100#define XFS_AT_UID 0x00000004
101#define XFS_AT_GID 0x00000008
102#define XFS_AT_FSID 0x00000010
103#define XFS_AT_NODEID 0x00000020
104#define XFS_AT_NLINK 0x00000040
105#define XFS_AT_SIZE 0x00000080
106#define XFS_AT_ATIME 0x00000100
107#define XFS_AT_MTIME 0x00000200
108#define XFS_AT_CTIME 0x00000400
109#define XFS_AT_RDEV 0x00000800
110#define XFS_AT_BLKSIZE 0x00001000
111#define XFS_AT_NBLOCKS 0x00002000
112#define XFS_AT_VCODE 0x00004000
113#define XFS_AT_MAC 0x00008000
114#define XFS_AT_UPDATIME 0x00010000
115#define XFS_AT_UPDMTIME 0x00020000
116#define XFS_AT_UPDCTIME 0x00040000
117#define XFS_AT_ACL 0x00080000
118#define XFS_AT_CAP 0x00100000
119#define XFS_AT_INF 0x00200000
120#define XFS_AT_XFLAGS 0x00400000
121#define XFS_AT_EXTSIZE 0x00800000
122#define XFS_AT_NEXTENTS 0x01000000
123#define XFS_AT_ANEXTENTS 0x02000000
124#define XFS_AT_PROJID 0x04000000
125#define XFS_AT_SIZE_NOPERM 0x08000000
126#define XFS_AT_GENCOUNT 0x10000000
127
128#define XFS_AT_ALL (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
129 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
130 XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME|XFS_AT_RDEV|\
131 XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|XFS_AT_MAC|\
132 XFS_AT_ACL|XFS_AT_CAP|XFS_AT_INF|XFS_AT_XFLAGS|XFS_AT_EXTSIZE|\
133 XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_PROJID|XFS_AT_GENCOUNT)
134
135#define XFS_AT_STAT (XFS_AT_TYPE|XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID|\
136 XFS_AT_FSID|XFS_AT_NODEID|XFS_AT_NLINK|XFS_AT_SIZE|\
137 XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME|XFS_AT_RDEV|\
138 XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_PROJID)
139
140#define XFS_AT_TIMES (XFS_AT_ATIME|XFS_AT_MTIME|XFS_AT_CTIME)
141
142#define XFS_AT_UPDTIMES (XFS_AT_UPDATIME|XFS_AT_UPDMTIME|XFS_AT_UPDCTIME)
143
144#define XFS_AT_NOSET (XFS_AT_NLINK|XFS_AT_RDEV|XFS_AT_FSID|XFS_AT_NODEID|\
145 XFS_AT_TYPE|XFS_AT_BLKSIZE|XFS_AT_NBLOCKS|XFS_AT_VCODE|\
146 XFS_AT_NEXTENTS|XFS_AT_ANEXTENTS|XFS_AT_GENCOUNT)
147 68
148extern void vn_init(void); 69extern void vn_init(void);
149extern int vn_revalidate(bhv_vnode_t *);
150 70
151/* 71/*
152 * Yeah, these don't take vnode anymore at all, all this should be 72 * Yeah, these don't take vnode anymore at all, all this should be
@@ -219,15 +139,6 @@ static inline void vn_atime_to_time_t(bhv_vnode_t *vp, time_t *tt)
219#define VN_DIRTY(vp) mapping_tagged(vn_to_inode(vp)->i_mapping, \ 139#define VN_DIRTY(vp) mapping_tagged(vn_to_inode(vp)->i_mapping, \
220 PAGECACHE_TAG_DIRTY) 140 PAGECACHE_TAG_DIRTY)
221 141
222/*
223 * Flags to vop_setattr/getattr.
224 */
225#define ATTR_UTIME 0x01 /* non-default utime(2) request */
226#define ATTR_DMI 0x08 /* invocation from a DMI function */
227#define ATTR_LAZY 0x80 /* set/get attributes lazily */
228#define ATTR_NONBLOCK 0x100 /* return EAGAIN if operation would block */
229#define ATTR_NOLOCK 0x200 /* Don't grab any conflicting locks */
230#define ATTR_NOSIZETOK 0x400 /* Don't get the SIZE token */
231 142
232/* 143/*
233 * Tracking vnode activity. 144 * Tracking vnode activity.
diff --git a/fs/xfs/linux-2.6/xfs_xattr.c b/fs/xfs/linux-2.6/xfs_xattr.c
new file mode 100644
index 000000000000..964621fde6ed
--- /dev/null
+++ b/fs/xfs/linux-2.6/xfs_xattr.c
@@ -0,0 +1,330 @@
1/*
2 * Copyright (C) 2008 Christoph Hellwig.
3 * Portions Copyright (C) 2000-2008 Silicon Graphics, Inc.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include "xfs.h"
20#include "xfs_da_btree.h"
21#include "xfs_bmap_btree.h"
22#include "xfs_inode.h"
23#include "xfs_attr.h"
24#include "xfs_attr_leaf.h"
25#include "xfs_acl.h"
26#include "xfs_vnodeops.h"
27
28#include <linux/posix_acl_xattr.h>
29#include <linux/xattr.h>
30
31
32/*
33 * ACL handling. Should eventually be moved into xfs_acl.c
34 */
35
36static int
37xfs_decode_acl(const char *name)
38{
39 if (strcmp(name, "posix_acl_access") == 0)
40 return _ACL_TYPE_ACCESS;
41 else if (strcmp(name, "posix_acl_default") == 0)
42 return _ACL_TYPE_DEFAULT;
43 return -EINVAL;
44}
45
46/*
47 * Get system extended attributes which at the moment only
48 * includes Posix ACLs.
49 */
50static int
51xfs_xattr_system_get(struct inode *inode, const char *name,
52 void *buffer, size_t size)
53{
54 int acl;
55
56 acl = xfs_decode_acl(name);
57 if (acl < 0)
58 return acl;
59
60 return xfs_acl_vget(inode, buffer, size, acl);
61}
62
63static int
64xfs_xattr_system_set(struct inode *inode, const char *name,
65 const void *value, size_t size, int flags)
66{
67 int acl;
68
69 acl = xfs_decode_acl(name);
70 if (acl < 0)
71 return acl;
72 if (flags & XATTR_CREATE)
73 return -EINVAL;
74
75 if (!value)
76 return xfs_acl_vremove(inode, acl);
77
78 return xfs_acl_vset(inode, (void *)value, size, acl);
79}
80
81static struct xattr_handler xfs_xattr_system_handler = {
82 .prefix = XATTR_SYSTEM_PREFIX,
83 .get = xfs_xattr_system_get,
84 .set = xfs_xattr_system_set,
85};
86
87
88/*
89 * Real xattr handling. The only difference between the namespaces is
90 * a flag passed to the low-level attr code.
91 */
92
93static int
94__xfs_xattr_get(struct inode *inode, const char *name,
95 void *value, size_t size, int xflags)
96{
97 struct xfs_inode *ip = XFS_I(inode);
98 int error, asize = size;
99
100 if (strcmp(name, "") == 0)
101 return -EINVAL;
102
103 /* Convert Linux syscall to XFS internal ATTR flags */
104 if (!size) {
105 xflags |= ATTR_KERNOVAL;
106 value = NULL;
107 }
108
109 error = -xfs_attr_get(ip, name, value, &asize, xflags);
110 if (error)
111 return error;
112 return asize;
113}
114
115static int
116__xfs_xattr_set(struct inode *inode, const char *name, const void *value,
117 size_t size, int flags, int xflags)
118{
119 struct xfs_inode *ip = XFS_I(inode);
120
121 if (strcmp(name, "") == 0)
122 return -EINVAL;
123
124 /* Convert Linux syscall to XFS internal ATTR flags */
125 if (flags & XATTR_CREATE)
126 xflags |= ATTR_CREATE;
127 if (flags & XATTR_REPLACE)
128 xflags |= ATTR_REPLACE;
129
130 if (!value)
131 return -xfs_attr_remove(ip, name, xflags);
132 return -xfs_attr_set(ip, name, (void *)value, size, xflags);
133}
134
135static int
136xfs_xattr_user_get(struct inode *inode, const char *name,
137 void *value, size_t size)
138{
139 return __xfs_xattr_get(inode, name, value, size, 0);
140}
141
142static int
143xfs_xattr_user_set(struct inode *inode, const char *name,
144 const void *value, size_t size, int flags)
145{
146 return __xfs_xattr_set(inode, name, value, size, flags, 0);
147}
148
149static struct xattr_handler xfs_xattr_user_handler = {
150 .prefix = XATTR_USER_PREFIX,
151 .get = xfs_xattr_user_get,
152 .set = xfs_xattr_user_set,
153};
154
155
156static int
157xfs_xattr_trusted_get(struct inode *inode, const char *name,
158 void *value, size_t size)
159{
160 return __xfs_xattr_get(inode, name, value, size, ATTR_ROOT);
161}
162
163static int
164xfs_xattr_trusted_set(struct inode *inode, const char *name,
165 const void *value, size_t size, int flags)
166{
167 return __xfs_xattr_set(inode, name, value, size, flags, ATTR_ROOT);
168}
169
170static struct xattr_handler xfs_xattr_trusted_handler = {
171 .prefix = XATTR_TRUSTED_PREFIX,
172 .get = xfs_xattr_trusted_get,
173 .set = xfs_xattr_trusted_set,
174};
175
176
177static int
178xfs_xattr_secure_get(struct inode *inode, const char *name,
179 void *value, size_t size)
180{
181 return __xfs_xattr_get(inode, name, value, size, ATTR_SECURE);
182}
183
184static int
185xfs_xattr_secure_set(struct inode *inode, const char *name,
186 const void *value, size_t size, int flags)
187{
188 return __xfs_xattr_set(inode, name, value, size, flags, ATTR_SECURE);
189}
190
191static struct xattr_handler xfs_xattr_security_handler = {
192 .prefix = XATTR_SECURITY_PREFIX,
193 .get = xfs_xattr_secure_get,
194 .set = xfs_xattr_secure_set,
195};
196
197
198struct xattr_handler *xfs_xattr_handlers[] = {
199 &xfs_xattr_user_handler,
200 &xfs_xattr_trusted_handler,
201 &xfs_xattr_security_handler,
202 &xfs_xattr_system_handler,
203 NULL
204};
205
206static unsigned int xfs_xattr_prefix_len(int flags)
207{
208 if (flags & XFS_ATTR_SECURE)
209 return sizeof("security");
210 else if (flags & XFS_ATTR_ROOT)
211 return sizeof("trusted");
212 else
213 return sizeof("user");
214}
215
216static const char *xfs_xattr_prefix(int flags)
217{
218 if (flags & XFS_ATTR_SECURE)
219 return xfs_xattr_security_handler.prefix;
220 else if (flags & XFS_ATTR_ROOT)
221 return xfs_xattr_trusted_handler.prefix;
222 else
223 return xfs_xattr_user_handler.prefix;
224}
225
226static int
227xfs_xattr_put_listent(struct xfs_attr_list_context *context, int flags,
228 char *name, int namelen, int valuelen, char *value)
229{
230 unsigned int prefix_len = xfs_xattr_prefix_len(flags);
231 char *offset;
232 int arraytop;
233
234 ASSERT(context->count >= 0);
235
236 /*
237 * Only show root namespace entries if we are actually allowed to
238 * see them.
239 */
240 if ((flags & XFS_ATTR_ROOT) && !capable(CAP_SYS_ADMIN))
241 return 0;
242
243 arraytop = context->count + prefix_len + namelen + 1;
244 if (arraytop > context->firstu) {
245 context->count = -1; /* insufficient space */
246 return 1;
247 }
248 offset = (char *)context->alist + context->count;
249 strncpy(offset, xfs_xattr_prefix(flags), prefix_len);
250 offset += prefix_len;
251 strncpy(offset, name, namelen); /* real name */
252 offset += namelen;
253 *offset = '\0';
254 context->count += prefix_len + namelen + 1;
255 return 0;
256}
257
258static int
259xfs_xattr_put_listent_sizes(struct xfs_attr_list_context *context, int flags,
260 char *name, int namelen, int valuelen, char *value)
261{
262 context->count += xfs_xattr_prefix_len(flags) + namelen + 1;
263 return 0;
264}
265
266static int
267list_one_attr(const char *name, const size_t len, void *data,
268 size_t size, ssize_t *result)
269{
270 char *p = data + *result;
271
272 *result += len;
273 if (!size)
274 return 0;
275 if (*result > size)
276 return -ERANGE;
277
278 strcpy(p, name);
279 return 0;
280}
281
282ssize_t
283xfs_vn_listxattr(struct dentry *dentry, char *data, size_t size)
284{
285 struct xfs_attr_list_context context;
286 struct attrlist_cursor_kern cursor = { 0 };
287 struct inode *inode = dentry->d_inode;
288 int error;
289
290 /*
291 * First read the regular on-disk attributes.
292 */
293 memset(&context, 0, sizeof(context));
294 context.dp = XFS_I(inode);
295 context.cursor = &cursor;
296 context.resynch = 1;
297 context.alist = data;
298 context.bufsize = size;
299 context.firstu = context.bufsize;
300
301 if (size)
302 context.put_listent = xfs_xattr_put_listent;
303 else
304 context.put_listent = xfs_xattr_put_listent_sizes;
305
306 xfs_attr_list_int(&context);
307 if (context.count < 0)
308 return -ERANGE;
309
310 /*
311 * Then add the two synthetic ACL attributes.
312 */
313 if (xfs_acl_vhasacl_access(inode)) {
314 error = list_one_attr(POSIX_ACL_XATTR_ACCESS,
315 strlen(POSIX_ACL_XATTR_ACCESS) + 1,
316 data, size, &context.count);
317 if (error)
318 return error;
319 }
320
321 if (xfs_acl_vhasacl_default(inode)) {
322 error = list_one_attr(POSIX_ACL_XATTR_DEFAULT,
323 strlen(POSIX_ACL_XATTR_DEFAULT) + 1,
324 data, size, &context.count);
325 if (error)
326 return error;
327 }
328
329 return context.count;
330}