Skip to content

Commit b41dae0

Browse files
committed
Merge tag 'xfs-5.4-merge-7' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
Pull xfs updates from Darrick Wong: "For this cycle we have the usual pile of cleanups and bug fixes, some performance improvements for online metadata scrubbing, massive speedups in the directory entry creation code, some performance improvement in the file ACL lookup code, a fix for a logging stall during mount, and fixes for concurrency problems. It has survived a couple of weeks of xfstests runs and merges cleanly. Summary: - Remove KM_SLEEP/KM_NOSLEEP. - Ensure that memory buffers for IO are properly sector-aligned to avoid problems that the block layer doesn't check. - Make the bmap scrubber more efficient in its record checking. - Don't crash xfs_db when superblock inode geometry is corrupt. - Fix btree key helper functions. - Remove unneeded error returns for things that can't fail. - Fix buffer logging bugs in repair. - Clean up iterator return values. - Speed up directory entry creation. - Enable allocation of xattr value memory buffer during lookup. - Fix readahead racing with truncate/punch hole. - Other minor cleanups. - Fix one AGI/AGF deadlock with RENAME_WHITEOUT. - More BUG -> WARN whackamole. - Fix various problems with the log failing to advance under certain circumstances, which results in stalls during mount" * tag 'xfs-5.4-merge-7' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux: (45 commits) xfs: push the grant head when the log head moves forward xfs: push iclog state cleaning into xlog_state_clean_log xfs: factor iclog state processing out of xlog_state_do_callback() xfs: factor callbacks out of xlog_state_do_callback() xfs: factor debug code out of xlog_state_do_callback() xfs: prevent CIL push holdoff in log recovery xfs: fix missed wakeup on l_flush_wait xfs: push the AIL in xlog_grant_head_wake xfs: Use WARN_ON_ONCE for bailout mount-operation xfs: Fix deadlock between AGI and AGF with RENAME_WHITEOUT xfs: define a flags field for the AG geometry ioctl structure xfs: add a xfs_valid_startblock helper xfs: remove the unused XFS_ALLOC_USERDATA flag xfs: cleanup xfs_fsb_to_db xfs: fix the dax supported check in xfs_ioctl_setattr_dax_invalidate xfs: Fix stale data exposure when readahead races with hole punch fs: Export generic_fadvise() mm: Handle MADV_WILLNEED through vfs_fadvise() xfs: allocate xattr buffer on demand xfs: consolidate attribute value copying ...
2 parents e6bc9de + 14e15f1 commit b41dae0

81 files changed

Lines changed: 1315 additions & 1089 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎fs/xfs/kmem.c‎

Lines changed: 59 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
* Copyright (c) 2000-2005 Silicon Graphics, Inc.
44
* All Rights Reserved.
55
*/
6-
#include <linux/sched/mm.h>
6+
#include "xfs.h"
77
#include <linux/backing-dev.h>
8-
#include "kmem.h"
98
#include "xfs_message.h"
9+
#include "xfs_trace.h"
1010

1111
void *
1212
kmem_alloc(size_t size, xfs_km_flags_t flags)
@@ -15,9 +15,11 @@ kmem_alloc(size_t size, xfs_km_flags_t flags)
1515
gfp_t lflags = kmem_flags_convert(flags);
1616
void *ptr;
1717

18+
trace_kmem_alloc(size, flags, _RET_IP_);
19+
1820
do {
1921
ptr = kmalloc(size, lflags);
20-
if (ptr || (flags & (KM_MAYFAIL|KM_NOSLEEP)))
22+
if (ptr || (flags & KM_MAYFAIL))
2123
return ptr;
2224
if (!(++retries % 100))
2325
xfs_err(NULL,
@@ -28,28 +30,24 @@ kmem_alloc(size_t size, xfs_km_flags_t flags)
2830
} while (1);
2931
}
3032

31-
void *
32-
kmem_alloc_large(size_t size, xfs_km_flags_t flags)
33+
34+
/*
35+
* __vmalloc() will allocate data pages and auxillary structures (e.g.
36+
* pagetables) with GFP_KERNEL, yet we may be under GFP_NOFS context here. Hence
37+
* we need to tell memory reclaim that we are in such a context via
38+
* PF_MEMALLOC_NOFS to prevent memory reclaim re-entering the filesystem here
39+
* and potentially deadlocking.
40+
*/
41+
static void *
42+
__kmem_vmalloc(size_t size, xfs_km_flags_t flags)
3343
{
3444
unsigned nofs_flag = 0;
3545
void *ptr;
36-
gfp_t lflags;
37-
38-
ptr = kmem_alloc(size, flags | KM_MAYFAIL);
39-
if (ptr)
40-
return ptr;
46+
gfp_t lflags = kmem_flags_convert(flags);
4147

42-
/*
43-
* __vmalloc() will allocate data pages and auxillary structures (e.g.
44-
* pagetables) with GFP_KERNEL, yet we may be under GFP_NOFS context
45-
* here. Hence we need to tell memory reclaim that we are in such a
46-
* context via PF_MEMALLOC_NOFS to prevent memory reclaim re-entering
47-
* the filesystem here and potentially deadlocking.
48-
*/
4948
if (flags & KM_NOFS)
5049
nofs_flag = memalloc_nofs_save();
5150

52-
lflags = kmem_flags_convert(flags);
5351
ptr = __vmalloc(size, lflags, PAGE_KERNEL);
5452

5553
if (flags & KM_NOFS)
@@ -58,16 +56,56 @@ kmem_alloc_large(size_t size, xfs_km_flags_t flags)
5856
return ptr;
5957
}
6058

59+
/*
60+
* Same as kmem_alloc_large, except we guarantee the buffer returned is aligned
61+
* to the @align_mask. We only guarantee alignment up to page size, we'll clamp
62+
* alignment at page size if it is larger. vmalloc always returns a PAGE_SIZE
63+
* aligned region.
64+
*/
65+
void *
66+
kmem_alloc_io(size_t size, int align_mask, xfs_km_flags_t flags)
67+
{
68+
void *ptr;
69+
70+
trace_kmem_alloc_io(size, flags, _RET_IP_);
71+
72+
if (WARN_ON_ONCE(align_mask >= PAGE_SIZE))
73+
align_mask = PAGE_SIZE - 1;
74+
75+
ptr = kmem_alloc(size, flags | KM_MAYFAIL);
76+
if (ptr) {
77+
if (!((uintptr_t)ptr & align_mask))
78+
return ptr;
79+
kfree(ptr);
80+
}
81+
return __kmem_vmalloc(size, flags);
82+
}
83+
84+
void *
85+
kmem_alloc_large(size_t size, xfs_km_flags_t flags)
86+
{
87+
void *ptr;
88+
89+
trace_kmem_alloc_large(size, flags, _RET_IP_);
90+
91+
ptr = kmem_alloc(size, flags | KM_MAYFAIL);
92+
if (ptr)
93+
return ptr;
94+
return __kmem_vmalloc(size, flags);
95+
}
96+
6197
void *
6298
kmem_realloc(const void *old, size_t newsize, xfs_km_flags_t flags)
6399
{
64100
int retries = 0;
65101
gfp_t lflags = kmem_flags_convert(flags);
66102
void *ptr;
67103

104+
trace_kmem_realloc(newsize, flags, _RET_IP_);
105+
68106
do {
69107
ptr = krealloc(old, newsize, lflags);
70-
if (ptr || (flags & (KM_MAYFAIL|KM_NOSLEEP)))
108+
if (ptr || (flags & KM_MAYFAIL))
71109
return ptr;
72110
if (!(++retries % 100))
73111
xfs_err(NULL,
@@ -85,9 +123,10 @@ kmem_zone_alloc(kmem_zone_t *zone, xfs_km_flags_t flags)
85123
gfp_t lflags = kmem_flags_convert(flags);
86124
void *ptr;
87125

126+
trace_kmem_zone_alloc(kmem_cache_size(zone), flags, _RET_IP_);
88127
do {
89128
ptr = kmem_cache_alloc(zone, lflags);
90-
if (ptr || (flags & (KM_MAYFAIL|KM_NOSLEEP)))
129+
if (ptr || (flags & KM_MAYFAIL))
91130
return ptr;
92131
if (!(++retries % 100))
93132
xfs_err(NULL,

‎fs/xfs/kmem.h‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
*/
1717

1818
typedef unsigned __bitwise xfs_km_flags_t;
19-
#define KM_SLEEP ((__force xfs_km_flags_t)0x0001u)
20-
#define KM_NOSLEEP ((__force xfs_km_flags_t)0x0002u)
2119
#define KM_NOFS ((__force xfs_km_flags_t)0x0004u)
2220
#define KM_MAYFAIL ((__force xfs_km_flags_t)0x0008u)
2321
#define KM_ZERO ((__force xfs_km_flags_t)0x0010u)
@@ -32,15 +30,11 @@ kmem_flags_convert(xfs_km_flags_t flags)
3230
{
3331
gfp_t lflags;
3432

35-
BUG_ON(flags & ~(KM_SLEEP|KM_NOSLEEP|KM_NOFS|KM_MAYFAIL|KM_ZERO));
33+
BUG_ON(flags & ~(KM_NOFS|KM_MAYFAIL|KM_ZERO));
3634

37-
if (flags & KM_NOSLEEP) {
38-
lflags = GFP_ATOMIC | __GFP_NOWARN;
39-
} else {
40-
lflags = GFP_KERNEL | __GFP_NOWARN;
41-
if (flags & KM_NOFS)
42-
lflags &= ~__GFP_FS;
43-
}
35+
lflags = GFP_KERNEL | __GFP_NOWARN;
36+
if (flags & KM_NOFS)
37+
lflags &= ~__GFP_FS;
4438

4539
/*
4640
* Default page/slab allocator behavior is to retry for ever
@@ -59,6 +53,7 @@ kmem_flags_convert(xfs_km_flags_t flags)
5953
}
6054

6155
extern void *kmem_alloc(size_t, xfs_km_flags_t);
56+
extern void *kmem_alloc_io(size_t size, int align_mask, xfs_km_flags_t flags);
6257
extern void *kmem_alloc_large(size_t size, xfs_km_flags_t);
6358
extern void *kmem_realloc(const void *, size_t, xfs_km_flags_t);
6459
static inline void kmem_free(const void *ptr)

‎fs/xfs/libxfs/xfs_alloc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2205,7 +2205,7 @@ xfs_defer_agfl_block(
22052205
ASSERT(xfs_bmap_free_item_zone != NULL);
22062206
ASSERT(oinfo != NULL);
22072207

2208-
new = kmem_zone_alloc(xfs_bmap_free_item_zone, KM_SLEEP);
2208+
new = kmem_zone_alloc(xfs_bmap_free_item_zone, 0);
22092209
new->xefi_startblock = XFS_AGB_TO_FSB(mp, agno, agbno);
22102210
new->xefi_blockcount = 1;
22112211
new->xefi_oinfo = *oinfo;

‎fs/xfs/libxfs/xfs_alloc.h‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,9 @@ typedef struct xfs_alloc_arg {
8181
/*
8282
* Defines for datatype
8383
*/
84-
#define XFS_ALLOC_USERDATA (1 << 0)/* allocation is for user data*/
85-
#define XFS_ALLOC_INITIAL_USER_DATA (1 << 1)/* special case start of file */
86-
#define XFS_ALLOC_USERDATA_ZERO (1 << 2)/* zero extent on allocation */
87-
#define XFS_ALLOC_NOBUSY (1 << 3)/* Busy extents not allowed */
84+
#define XFS_ALLOC_INITIAL_USER_DATA (1 << 0)/* special case start of file */
85+
#define XFS_ALLOC_USERDATA_ZERO (1 << 1)/* zero extent on allocation */
86+
#define XFS_ALLOC_NOBUSY (1 << 2)/* Busy extents not allowed */
8887

8988
static inline bool
9089
xfs_alloc_is_userdata(int datatype)

‎fs/xfs/libxfs/xfs_attr.c‎

Lines changed: 55 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ xfs_inode_hasattr(
9797
* Overall external interface routines.
9898
*========================================================================*/
9999

100-
/* Retrieve an extended attribute and its value. Must have ilock. */
100+
/*
101+
* Retrieve an extended attribute and its value. Must have ilock.
102+
* Returns 0 on successful retrieval, otherwise an error.
103+
*/
101104
int
102105
xfs_attr_get_ilocked(
103106
struct xfs_inode *ip,
@@ -115,19 +118,37 @@ xfs_attr_get_ilocked(
115118
return xfs_attr_node_get(args);
116119
}
117120

118-
/* Retrieve an extended attribute by name, and its value. */
121+
/*
122+
* Retrieve an extended attribute by name, and its value if requested.
123+
*
124+
* If ATTR_KERNOVAL is set in @flags, then the caller does not want the value,
125+
* just an indication whether the attribute exists and the size of the value if
126+
* it exists. The size is returned in @valuelenp,
127+
*
128+
* If the attribute is found, but exceeds the size limit set by the caller in
129+
* @valuelenp, return -ERANGE with the size of the attribute that was found in
130+
* @valuelenp.
131+
*
132+
* If ATTR_ALLOC is set in @flags, allocate the buffer for the value after
133+
* existence of the attribute has been determined. On success, return that
134+
* buffer to the caller and leave them to free it. On failure, free any
135+
* allocated buffer and ensure the buffer pointer returned to the caller is
136+
* null.
137+
*/
119138
int
120139
xfs_attr_get(
121140
struct xfs_inode *ip,
122141
const unsigned char *name,
123-
unsigned char *value,
142+
unsigned char **value,
124143
int *valuelenp,
125144
int flags)
126145
{
127146
struct xfs_da_args args;
128147
uint lock_mode;
129148
int error;
130149

150+
ASSERT((flags & (ATTR_ALLOC | ATTR_KERNOVAL)) || *value);
151+
131152
XFS_STATS_INC(ip->i_mount, xs_attr_get);
132153

133154
if (XFS_FORCED_SHUTDOWN(ip->i_mount))
@@ -137,17 +158,29 @@ xfs_attr_get(
137158
if (error)
138159
return error;
139160

140-
args.value = value;
141-
args.valuelen = *valuelenp;
142161
/* Entirely possible to look up a name which doesn't exist */
143162
args.op_flags = XFS_DA_OP_OKNOENT;
163+
if (flags & ATTR_ALLOC)
164+
args.op_flags |= XFS_DA_OP_ALLOCVAL;
165+
else
166+
args.value = *value;
167+
args.valuelen = *valuelenp;
144168

145169
lock_mode = xfs_ilock_attr_map_shared(ip);
146170
error = xfs_attr_get_ilocked(ip, &args);
147171
xfs_iunlock(ip, lock_mode);
148-
149172
*valuelenp = args.valuelen;
150-
return error == -EEXIST ? 0 : error;
173+
174+
/* on error, we have to clean up allocated value buffers */
175+
if (error) {
176+
if (flags & ATTR_ALLOC) {
177+
kmem_free(args.value);
178+
*value = NULL;
179+
}
180+
return error;
181+
}
182+
*value = args.value;
183+
return 0;
151184
}
152185

153186
/*
@@ -768,6 +801,8 @@ xfs_attr_leaf_removename(
768801
*
769802
* This leaf block cannot have a "remote" value, we only call this routine
770803
* if bmap_one_block() says there is only one block (ie: no remote blks).
804+
*
805+
* Returns 0 on successful retrieval, otherwise an error.
771806
*/
772807
STATIC int
773808
xfs_attr_leaf_get(xfs_da_args_t *args)
@@ -789,9 +824,6 @@ xfs_attr_leaf_get(xfs_da_args_t *args)
789824
}
790825
error = xfs_attr3_leaf_getvalue(bp, args);
791826
xfs_trans_brelse(args->trans, bp);
792-
if (!error && (args->rmtblkno > 0) && !(args->flags & ATTR_KERNOVAL)) {
793-
error = xfs_attr_rmtval_get(args);
794-
}
795827
return error;
796828
}
797829

@@ -1268,11 +1300,13 @@ xfs_attr_refillstate(xfs_da_state_t *state)
12681300
}
12691301

12701302
/*
1271-
* Look up a filename in a node attribute list.
1303+
* Retrieve the attribute data from a node attribute list.
12721304
*
12731305
* This routine gets called for any attribute fork that has more than one
12741306
* block, ie: both true Btree attr lists and for single-leaf-blocks with
12751307
* "remote" values taking up more blocks.
1308+
*
1309+
* Returns 0 on successful retrieval, otherwise an error.
12761310
*/
12771311
STATIC int
12781312
xfs_attr_node_get(xfs_da_args_t *args)
@@ -1294,24 +1328,21 @@ xfs_attr_node_get(xfs_da_args_t *args)
12941328
error = xfs_da3_node_lookup_int(state, &retval);
12951329
if (error) {
12961330
retval = error;
1297-
} else if (retval == -EEXIST) {
1298-
blk = &state->path.blk[ state->path.active-1 ];
1299-
ASSERT(blk->bp != NULL);
1300-
ASSERT(blk->magic == XFS_ATTR_LEAF_MAGIC);
1301-
1302-
/*
1303-
* Get the value, local or "remote"
1304-
*/
1305-
retval = xfs_attr3_leaf_getvalue(blk->bp, args);
1306-
if (!retval && (args->rmtblkno > 0)
1307-
&& !(args->flags & ATTR_KERNOVAL)) {
1308-
retval = xfs_attr_rmtval_get(args);
1309-
}
1331+
goto out_release;
13101332
}
1333+
if (retval != -EEXIST)
1334+
goto out_release;
1335+
1336+
/*
1337+
* Get the value, local or "remote"
1338+
*/
1339+
blk = &state->path.blk[state->path.active - 1];
1340+
retval = xfs_attr3_leaf_getvalue(blk->bp, args);
13111341

13121342
/*
13131343
* If not in a transaction, we have to release all the buffers.
13141344
*/
1345+
out_release:
13151346
for (i = 0; i < state->path.active; i++) {
13161347
xfs_trans_brelse(args->trans, state->path.blk[i].bp);
13171348
state->path.blk[i].bp = NULL;

‎fs/xfs/libxfs/xfs_attr.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ struct xfs_attr_list_context;
3737
#define ATTR_KERNOVAL 0x2000 /* [kernel] get attr size only, not value */
3838

3939
#define ATTR_INCOMPLETE 0x4000 /* [kernel] return INCOMPLETE attr keys */
40+
#define ATTR_ALLOC 0x8000 /* allocate xattr buffer on demand */
4041

4142
#define XFS_ATTR_FLAGS \
4243
{ ATTR_DONTFOLLOW, "DONTFOLLOW" }, \
@@ -47,7 +48,8 @@ struct xfs_attr_list_context;
4748
{ ATTR_REPLACE, "REPLACE" }, \
4849
{ ATTR_KERNOTIME, "KERNOTIME" }, \
4950
{ ATTR_KERNOVAL, "KERNOVAL" }, \
50-
{ ATTR_INCOMPLETE, "INCOMPLETE" }
51+
{ ATTR_INCOMPLETE, "INCOMPLETE" }, \
52+
{ ATTR_ALLOC, "ALLOC" }
5153

5254
/*
5355
* The maximum size (into the kernel or returned from the kernel) of an
@@ -143,7 +145,7 @@ int xfs_attr_list_int(struct xfs_attr_list_context *);
143145
int xfs_inode_hasattr(struct xfs_inode *ip);
144146
int xfs_attr_get_ilocked(struct xfs_inode *ip, struct xfs_da_args *args);
145147
int xfs_attr_get(struct xfs_inode *ip, const unsigned char *name,
146-
unsigned char *value, int *valuelenp, int flags);
148+
unsigned char **value, int *valuelenp, int flags);
147149
int xfs_attr_set(struct xfs_inode *dp, const unsigned char *name,
148150
unsigned char *value, int valuelen, int flags);
149151
int xfs_attr_set_args(struct xfs_da_args *args);

0 commit comments

Comments
 (0)