aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_attr.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/xfs/xfs_attr.c')
-rw-r--r--fs/xfs/xfs_attr.c171
1 files changed, 46 insertions, 125 deletions
diff --git a/fs/xfs/xfs_attr.c b/fs/xfs/xfs_attr.c
index 4ece1906bd41..b9c196a53c42 100644
--- a/fs/xfs/xfs_attr.c
+++ b/fs/xfs/xfs_attr.c
@@ -47,6 +47,7 @@
47#include "xfs_trans_space.h" 47#include "xfs_trans_space.h"
48#include "xfs_rw.h" 48#include "xfs_rw.h"
49#include "xfs_vnodeops.h" 49#include "xfs_vnodeops.h"
50#include "xfs_trace.h"
50 51
51/* 52/*
52 * xfs_attr.c 53 * xfs_attr.c
@@ -89,19 +90,15 @@ STATIC int xfs_attr_rmtval_remove(xfs_da_args_t *args);
89 90
90#define ATTR_RMTVALUE_MAPSIZE 1 /* # of map entries at once */ 91#define ATTR_RMTVALUE_MAPSIZE 1 /* # of map entries at once */
91 92
92#if defined(XFS_ATTR_TRACE)
93ktrace_t *xfs_attr_trace_buf;
94#endif
95
96STATIC int 93STATIC int
97xfs_attr_name_to_xname( 94xfs_attr_name_to_xname(
98 struct xfs_name *xname, 95 struct xfs_name *xname,
99 const char *aname) 96 const unsigned char *aname)
100{ 97{
101 if (!aname) 98 if (!aname)
102 return EINVAL; 99 return EINVAL;
103 xname->name = aname; 100 xname->name = aname;
104 xname->len = strlen(aname); 101 xname->len = strlen((char *)aname);
105 if (xname->len >= MAXNAMELEN) 102 if (xname->len >= MAXNAMELEN)
106 return EFAULT; /* match IRIX behaviour */ 103 return EFAULT; /* match IRIX behaviour */
107 104
@@ -123,9 +120,13 @@ xfs_inode_hasattr(
123 * Overall external interface routines. 120 * Overall external interface routines.
124 *========================================================================*/ 121 *========================================================================*/
125 122
126int 123STATIC int
127xfs_attr_fetch(xfs_inode_t *ip, struct xfs_name *name, 124xfs_attr_get_int(
128 char *value, int *valuelenp, int flags) 125 struct xfs_inode *ip,
126 struct xfs_name *name,
127 unsigned char *value,
128 int *valuelenp,
129 int flags)
129{ 130{
130 xfs_da_args_t args; 131 xfs_da_args_t args;
131 int error; 132 int error;
@@ -170,8 +171,8 @@ xfs_attr_fetch(xfs_inode_t *ip, struct xfs_name *name,
170int 171int
171xfs_attr_get( 172xfs_attr_get(
172 xfs_inode_t *ip, 173 xfs_inode_t *ip,
173 const char *name, 174 const unsigned char *name,
174 char *value, 175 unsigned char *value,
175 int *valuelenp, 176 int *valuelenp,
176 int flags) 177 int flags)
177{ 178{
@@ -188,7 +189,7 @@ xfs_attr_get(
188 return error; 189 return error;
189 190
190 xfs_ilock(ip, XFS_ILOCK_SHARED); 191 xfs_ilock(ip, XFS_ILOCK_SHARED);
191 error = xfs_attr_fetch(ip, &xname, value, valuelenp, flags); 192 error = xfs_attr_get_int(ip, &xname, value, valuelenp, flags);
192 xfs_iunlock(ip, XFS_ILOCK_SHARED); 193 xfs_iunlock(ip, XFS_ILOCK_SHARED);
193 return(error); 194 return(error);
194} 195}
@@ -196,7 +197,7 @@ xfs_attr_get(
196/* 197/*
197 * Calculate how many blocks we need for the new attribute, 198 * Calculate how many blocks we need for the new attribute,
198 */ 199 */
199int 200STATIC int
200xfs_attr_calc_size( 201xfs_attr_calc_size(
201 struct xfs_inode *ip, 202 struct xfs_inode *ip,
202 int namelen, 203 int namelen,
@@ -234,8 +235,12 @@ xfs_attr_calc_size(
234} 235}
235 236
236STATIC int 237STATIC int
237xfs_attr_set_int(xfs_inode_t *dp, struct xfs_name *name, 238xfs_attr_set_int(
238 char *value, int valuelen, int flags) 239 struct xfs_inode *dp,
240 struct xfs_name *name,
241 unsigned char *value,
242 int valuelen,
243 int flags)
239{ 244{
240 xfs_da_args_t args; 245 xfs_da_args_t args;
241 xfs_fsblock_t firstblock; 246 xfs_fsblock_t firstblock;
@@ -451,8 +456,8 @@ out:
451int 456int
452xfs_attr_set( 457xfs_attr_set(
453 xfs_inode_t *dp, 458 xfs_inode_t *dp,
454 const char *name, 459 const unsigned char *name,
455 char *value, 460 unsigned char *value,
456 int valuelen, 461 int valuelen,
457 int flags) 462 int flags)
458{ 463{
@@ -599,7 +604,7 @@ out:
599int 604int
600xfs_attr_remove( 605xfs_attr_remove(
601 xfs_inode_t *dp, 606 xfs_inode_t *dp,
602 const char *name, 607 const unsigned char *name,
603 int flags) 608 int flags)
604{ 609{
605 int error; 610 int error;
@@ -636,7 +641,6 @@ xfs_attr_list_int(xfs_attr_list_context_t *context)
636 return EIO; 641 return EIO;
637 642
638 xfs_ilock(dp, XFS_ILOCK_SHARED); 643 xfs_ilock(dp, XFS_ILOCK_SHARED);
639 xfs_attr_trace_l_c("syscall start", context);
640 644
641 /* 645 /*
642 * Decide on what work routines to call based on the inode size. 646 * Decide on what work routines to call based on the inode size.
@@ -652,7 +656,6 @@ xfs_attr_list_int(xfs_attr_list_context_t *context)
652 } 656 }
653 657
654 xfs_iunlock(dp, XFS_ILOCK_SHARED); 658 xfs_iunlock(dp, XFS_ILOCK_SHARED);
655 xfs_attr_trace_l_c("syscall end", context);
656 659
657 return error; 660 return error;
658} 661}
@@ -670,9 +673,13 @@ xfs_attr_list_int(xfs_attr_list_context_t *context)
670 */ 673 */
671/*ARGSUSED*/ 674/*ARGSUSED*/
672STATIC int 675STATIC int
673xfs_attr_put_listent(xfs_attr_list_context_t *context, int flags, 676xfs_attr_put_listent(
674 char *name, int namelen, 677 xfs_attr_list_context_t *context,
675 int valuelen, char *value) 678 int flags,
679 unsigned char *name,
680 int namelen,
681 int valuelen,
682 unsigned char *value)
676{ 683{
677 struct attrlist *alist = (struct attrlist *)context->alist; 684 struct attrlist *alist = (struct attrlist *)context->alist;
678 attrlist_ent_t *aep; 685 attrlist_ent_t *aep;
@@ -698,7 +705,7 @@ xfs_attr_put_listent(xfs_attr_list_context_t *context, int flags,
698 context->count * sizeof(alist->al_offset[0]); 705 context->count * sizeof(alist->al_offset[0]);
699 context->firstu -= ATTR_ENTSIZE(namelen); 706 context->firstu -= ATTR_ENTSIZE(namelen);
700 if (context->firstu < arraytop) { 707 if (context->firstu < arraytop) {
701 xfs_attr_trace_l_c("buffer full", context); 708 trace_xfs_attr_list_full(context);
702 alist->al_more = 1; 709 alist->al_more = 1;
703 context->seen_enough = 1; 710 context->seen_enough = 1;
704 return 1; 711 return 1;
@@ -710,7 +717,7 @@ xfs_attr_put_listent(xfs_attr_list_context_t *context, int flags,
710 aep->a_name[namelen] = 0; 717 aep->a_name[namelen] = 0;
711 alist->al_offset[context->count++] = context->firstu; 718 alist->al_offset[context->count++] = context->firstu;
712 alist->al_count = context->count; 719 alist->al_count = context->count;
713 xfs_attr_trace_l_c("add", context); 720 trace_xfs_attr_list_add(context);
714 return 0; 721 return 0;
715} 722}
716 723
@@ -1849,7 +1856,7 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)
1849 node = bp->data; 1856 node = bp->data;
1850 switch (be16_to_cpu(node->hdr.info.magic)) { 1857 switch (be16_to_cpu(node->hdr.info.magic)) {
1851 case XFS_DA_NODE_MAGIC: 1858 case XFS_DA_NODE_MAGIC:
1852 xfs_attr_trace_l_cn("wrong blk", context, node); 1859 trace_xfs_attr_list_wrong_blk(context);
1853 xfs_da_brelse(NULL, bp); 1860 xfs_da_brelse(NULL, bp);
1854 bp = NULL; 1861 bp = NULL;
1855 break; 1862 break;
@@ -1857,20 +1864,18 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)
1857 leaf = bp->data; 1864 leaf = bp->data;
1858 if (cursor->hashval > be32_to_cpu(leaf->entries[ 1865 if (cursor->hashval > be32_to_cpu(leaf->entries[
1859 be16_to_cpu(leaf->hdr.count)-1].hashval)) { 1866 be16_to_cpu(leaf->hdr.count)-1].hashval)) {
1860 xfs_attr_trace_l_cl("wrong blk", 1867 trace_xfs_attr_list_wrong_blk(context);
1861 context, leaf);
1862 xfs_da_brelse(NULL, bp); 1868 xfs_da_brelse(NULL, bp);
1863 bp = NULL; 1869 bp = NULL;
1864 } else if (cursor->hashval <= 1870 } else if (cursor->hashval <=
1865 be32_to_cpu(leaf->entries[0].hashval)) { 1871 be32_to_cpu(leaf->entries[0].hashval)) {
1866 xfs_attr_trace_l_cl("maybe wrong blk", 1872 trace_xfs_attr_list_wrong_blk(context);
1867 context, leaf);
1868 xfs_da_brelse(NULL, bp); 1873 xfs_da_brelse(NULL, bp);
1869 bp = NULL; 1874 bp = NULL;
1870 } 1875 }
1871 break; 1876 break;
1872 default: 1877 default:
1873 xfs_attr_trace_l_c("wrong blk - ??", context); 1878 trace_xfs_attr_list_wrong_blk(context);
1874 xfs_da_brelse(NULL, bp); 1879 xfs_da_brelse(NULL, bp);
1875 bp = NULL; 1880 bp = NULL;
1876 } 1881 }
@@ -1915,8 +1920,8 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)
1915 if (cursor->hashval 1920 if (cursor->hashval
1916 <= be32_to_cpu(btree->hashval)) { 1921 <= be32_to_cpu(btree->hashval)) {
1917 cursor->blkno = be32_to_cpu(btree->before); 1922 cursor->blkno = be32_to_cpu(btree->before);
1918 xfs_attr_trace_l_cb("descending", 1923 trace_xfs_attr_list_node_descend(context,
1919 context, btree); 1924 btree);
1920 break; 1925 break;
1921 } 1926 }
1922 } 1927 }
@@ -1983,7 +1988,7 @@ xfs_attr_rmtval_get(xfs_da_args_t *args)
1983 xfs_bmbt_irec_t map[ATTR_RMTVALUE_MAPSIZE]; 1988 xfs_bmbt_irec_t map[ATTR_RMTVALUE_MAPSIZE];
1984 xfs_mount_t *mp; 1989 xfs_mount_t *mp;
1985 xfs_daddr_t dblkno; 1990 xfs_daddr_t dblkno;
1986 xfs_caddr_t dst; 1991 void *dst;
1987 xfs_buf_t *bp; 1992 xfs_buf_t *bp;
1988 int nmap, error, tmp, valuelen, blkcnt, i; 1993 int nmap, error, tmp, valuelen, blkcnt, i;
1989 xfs_dablk_t lblkno; 1994 xfs_dablk_t lblkno;
@@ -2010,15 +2015,14 @@ xfs_attr_rmtval_get(xfs_da_args_t *args)
2010 dblkno = XFS_FSB_TO_DADDR(mp, map[i].br_startblock); 2015 dblkno = XFS_FSB_TO_DADDR(mp, map[i].br_startblock);
2011 blkcnt = XFS_FSB_TO_BB(mp, map[i].br_blockcount); 2016 blkcnt = XFS_FSB_TO_BB(mp, map[i].br_blockcount);
2012 error = xfs_read_buf(mp, mp->m_ddev_targp, dblkno, 2017 error = xfs_read_buf(mp, mp->m_ddev_targp, dblkno,
2013 blkcnt, 2018 blkcnt, XBF_LOCK | XBF_DONT_BLOCK,
2014 XFS_BUF_LOCK | XBF_DONT_BLOCK,
2015 &bp); 2019 &bp);
2016 if (error) 2020 if (error)
2017 return(error); 2021 return(error);
2018 2022
2019 tmp = (valuelen < XFS_BUF_SIZE(bp)) 2023 tmp = (valuelen < XFS_BUF_SIZE(bp))
2020 ? valuelen : XFS_BUF_SIZE(bp); 2024 ? valuelen : XFS_BUF_SIZE(bp);
2021 xfs_biomove(bp, 0, tmp, dst, XFS_B_READ); 2025 xfs_biomove(bp, 0, tmp, dst, XBF_READ);
2022 xfs_buf_relse(bp); 2026 xfs_buf_relse(bp);
2023 dst += tmp; 2027 dst += tmp;
2024 valuelen -= tmp; 2028 valuelen -= tmp;
@@ -2042,7 +2046,7 @@ xfs_attr_rmtval_set(xfs_da_args_t *args)
2042 xfs_inode_t *dp; 2046 xfs_inode_t *dp;
2043 xfs_bmbt_irec_t map; 2047 xfs_bmbt_irec_t map;
2044 xfs_daddr_t dblkno; 2048 xfs_daddr_t dblkno;
2045 xfs_caddr_t src; 2049 void *src;
2046 xfs_buf_t *bp; 2050 xfs_buf_t *bp;
2047 xfs_dablk_t lblkno; 2051 xfs_dablk_t lblkno;
2048 int blkcnt, valuelen, nmap, error, tmp, committed; 2052 int blkcnt, valuelen, nmap, error, tmp, committed;
@@ -2143,14 +2147,14 @@ xfs_attr_rmtval_set(xfs_da_args_t *args)
2143 dblkno = XFS_FSB_TO_DADDR(mp, map.br_startblock), 2147 dblkno = XFS_FSB_TO_DADDR(mp, map.br_startblock),
2144 blkcnt = XFS_FSB_TO_BB(mp, map.br_blockcount); 2148 blkcnt = XFS_FSB_TO_BB(mp, map.br_blockcount);
2145 2149
2146 bp = xfs_buf_get_flags(mp->m_ddev_targp, dblkno, blkcnt, 2150 bp = xfs_buf_get(mp->m_ddev_targp, dblkno, blkcnt,
2147 XFS_BUF_LOCK | XBF_DONT_BLOCK); 2151 XBF_LOCK | XBF_DONT_BLOCK);
2148 ASSERT(bp); 2152 ASSERT(bp);
2149 ASSERT(!XFS_BUF_GETERROR(bp)); 2153 ASSERT(!XFS_BUF_GETERROR(bp));
2150 2154
2151 tmp = (valuelen < XFS_BUF_SIZE(bp)) ? valuelen : 2155 tmp = (valuelen < XFS_BUF_SIZE(bp)) ? valuelen :
2152 XFS_BUF_SIZE(bp); 2156 XFS_BUF_SIZE(bp);
2153 xfs_biomove(bp, 0, tmp, src, XFS_B_WRITE); 2157 xfs_biomove(bp, 0, tmp, src, XBF_WRITE);
2154 if (tmp < XFS_BUF_SIZE(bp)) 2158 if (tmp < XFS_BUF_SIZE(bp))
2155 xfs_biozero(bp, tmp, XFS_BUF_SIZE(bp) - tmp); 2159 xfs_biozero(bp, tmp, XFS_BUF_SIZE(bp) - tmp);
2156 if ((error = xfs_bwrite(mp, bp))) {/* GROT: NOTE: synchronous write */ 2160 if ((error = xfs_bwrite(mp, bp))) {/* GROT: NOTE: synchronous write */
@@ -2211,8 +2215,7 @@ xfs_attr_rmtval_remove(xfs_da_args_t *args)
2211 /* 2215 /*
2212 * If the "remote" value is in the cache, remove it. 2216 * If the "remote" value is in the cache, remove it.
2213 */ 2217 */
2214 bp = xfs_incore(mp->m_ddev_targp, dblkno, blkcnt, 2218 bp = xfs_incore(mp->m_ddev_targp, dblkno, blkcnt, XBF_TRYLOCK);
2215 XFS_INCORE_TRYLOCK);
2216 if (bp) { 2219 if (bp) {
2217 XFS_BUF_STALE(bp); 2220 XFS_BUF_STALE(bp);
2218 XFS_BUF_UNDELAYWRITE(bp); 2221 XFS_BUF_UNDELAYWRITE(bp);
@@ -2266,85 +2269,3 @@ xfs_attr_rmtval_remove(xfs_da_args_t *args)
2266 } 2269 }
2267 return(0); 2270 return(0);
2268} 2271}
2269
2270#if defined(XFS_ATTR_TRACE)
2271/*
2272 * Add a trace buffer entry for an attr_list context structure.
2273 */
2274void
2275xfs_attr_trace_l_c(char *where, struct xfs_attr_list_context *context)
2276{
2277 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_C, where, context,
2278 (__psunsigned_t)NULL,
2279 (__psunsigned_t)NULL,
2280 (__psunsigned_t)NULL);
2281}
2282
2283/*
2284 * Add a trace buffer entry for a context structure and a Btree node.
2285 */
2286void
2287xfs_attr_trace_l_cn(char *where, struct xfs_attr_list_context *context,
2288 struct xfs_da_intnode *node)
2289{
2290 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CN, where, context,
2291 (__psunsigned_t)be16_to_cpu(node->hdr.count),
2292 (__psunsigned_t)be32_to_cpu(node->btree[0].hashval),
2293 (__psunsigned_t)be32_to_cpu(node->btree[
2294 be16_to_cpu(node->hdr.count)-1].hashval));
2295}
2296
2297/*
2298 * Add a trace buffer entry for a context structure and a Btree element.
2299 */
2300void
2301xfs_attr_trace_l_cb(char *where, struct xfs_attr_list_context *context,
2302 struct xfs_da_node_entry *btree)
2303{
2304 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CB, where, context,
2305 (__psunsigned_t)be32_to_cpu(btree->hashval),
2306 (__psunsigned_t)be32_to_cpu(btree->before),
2307 (__psunsigned_t)NULL);
2308}
2309
2310/*
2311 * Add a trace buffer entry for a context structure and a leaf block.
2312 */
2313void
2314xfs_attr_trace_l_cl(char *where, struct xfs_attr_list_context *context,
2315 struct xfs_attr_leafblock *leaf)
2316{
2317 xfs_attr_trace_enter(XFS_ATTR_KTRACE_L_CL, where, context,
2318 (__psunsigned_t)be16_to_cpu(leaf->hdr.count),
2319 (__psunsigned_t)be32_to_cpu(leaf->entries[0].hashval),
2320 (__psunsigned_t)be32_to_cpu(leaf->entries[
2321 be16_to_cpu(leaf->hdr.count)-1].hashval));
2322}
2323
2324/*
2325 * Add a trace buffer entry for the arguments given to the routine,
2326 * generic form.
2327 */
2328void
2329xfs_attr_trace_enter(int type, char *where,
2330 struct xfs_attr_list_context *context,
2331 __psunsigned_t a13, __psunsigned_t a14,
2332 __psunsigned_t a15)
2333{
2334 ASSERT(xfs_attr_trace_buf);
2335 ktrace_enter(xfs_attr_trace_buf, (void *)((__psunsigned_t)type),
2336 (void *)((__psunsigned_t)where),
2337 (void *)((__psunsigned_t)context->dp),
2338 (void *)((__psunsigned_t)context->cursor->hashval),
2339 (void *)((__psunsigned_t)context->cursor->blkno),
2340 (void *)((__psunsigned_t)context->cursor->offset),
2341 (void *)((__psunsigned_t)context->alist),
2342 (void *)((__psunsigned_t)context->bufsize),
2343 (void *)((__psunsigned_t)context->count),
2344 (void *)((__psunsigned_t)context->firstu),
2345 NULL,
2346 (void *)((__psunsigned_t)context->dupcnt),
2347 (void *)((__psunsigned_t)context->flags),
2348 (void *)a13, (void *)a14, (void *)a15);
2349}
2350#endif /* XFS_ATTR_TRACE */