Skip to content

Commit 8a0599d

Browse files
committed
Merge branch 'for-linus' of git://oss.sgi.com/xfs/xfs
* 'for-linus' of git://oss.sgi.com/xfs/xfs: xfs: correctly decrement the extent buffer index in xfs_bmap_del_extent xfs: check for valid indices in xfs_iext_get_ext and xfs_iext_idx_to_irec xfs: fix up asserts in xfs_iflush_fork xfs: do not do pointer arithmetic on extent records xfs: do not use unchecked extent indices in xfs_bunmapi xfs: do not use unchecked extent indices in xfs_bmapi xfs: do not use unchecked extent indices in xfs_bmap_add_extent_* xfs: remove if_lastex xfs: remove the unused XFS_BMAPI_RSVBLOCKS flag xfs: do not discard alloc btree blocks xfs: add online discard support
2 parents 35806b4 + 233eebb commit 8a0599d

15 files changed

Lines changed: 366 additions & 318 deletions

File tree

‎Documentation/filesystems/xfs.txt‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ When mounting an XFS filesystem, the following options are accepted.
3939
drive level write caching to be enabled, for devices that
4040
support write barriers.
4141

42+
discard
43+
Issue command to let the block device reclaim space freed by the
44+
filesystem. This is useful for SSD devices, thinly provisioned
45+
LUNs and virtual machine images, but may have a performance
46+
impact. This option is incompatible with the nodelaylog option.
47+
4248
dmapi
4349
Enable the DMAPI (Data Management API) event callouts.
4450
Use with the "mtpt" option.

‎fs/xfs/linux-2.6/xfs_discard.c‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,32 @@ xfs_ioc_trim(
191191
return -XFS_ERROR(EFAULT);
192192
return 0;
193193
}
194+
195+
int
196+
xfs_discard_extents(
197+
struct xfs_mount *mp,
198+
struct list_head *list)
199+
{
200+
struct xfs_busy_extent *busyp;
201+
int error = 0;
202+
203+
list_for_each_entry(busyp, list, list) {
204+
trace_xfs_discard_extent(mp, busyp->agno, busyp->bno,
205+
busyp->length);
206+
207+
error = -blkdev_issue_discard(mp->m_ddev_targp->bt_bdev,
208+
XFS_AGB_TO_DADDR(mp, busyp->agno, busyp->bno),
209+
XFS_FSB_TO_BB(mp, busyp->length),
210+
GFP_NOFS, 0);
211+
if (error && error != EOPNOTSUPP) {
212+
xfs_info(mp,
213+
"discard failed for extent [0x%llu,%u], error %d",
214+
(unsigned long long)busyp->bno,
215+
busyp->length,
216+
error);
217+
return error;
218+
}
219+
}
220+
221+
return 0;
222+
}

‎fs/xfs/linux-2.6/xfs_discard.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
#define XFS_DISCARD_H 1
33

44
struct fstrim_range;
5+
struct list_head;
56

67
extern int xfs_ioc_trim(struct xfs_mount *, struct fstrim_range __user *);
8+
extern int xfs_discard_extents(struct xfs_mount *, struct list_head *);
79

810
#endif /* XFS_DISCARD_H */

‎fs/xfs/linux-2.6/xfs_super.c‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,10 @@ mempool_t *xfs_ioend_pool;
110110
#define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
111111
#define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
112112
#define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
113-
#define MNTOPT_DELAYLOG "delaylog" /* Delayed loging enabled */
114-
#define MNTOPT_NODELAYLOG "nodelaylog" /* Delayed loging disabled */
113+
#define MNTOPT_DELAYLOG "delaylog" /* Delayed logging enabled */
114+
#define MNTOPT_NODELAYLOG "nodelaylog" /* Delayed logging disabled */
115+
#define MNTOPT_DISCARD "discard" /* Discard unused blocks */
116+
#define MNTOPT_NODISCARD "nodiscard" /* Do not discard unused blocks */
115117

116118
/*
117119
* Table driven mount option parser.
@@ -355,6 +357,10 @@ xfs_parseargs(
355357
mp->m_flags |= XFS_MOUNT_DELAYLOG;
356358
} else if (!strcmp(this_char, MNTOPT_NODELAYLOG)) {
357359
mp->m_flags &= ~XFS_MOUNT_DELAYLOG;
360+
} else if (!strcmp(this_char, MNTOPT_DISCARD)) {
361+
mp->m_flags |= XFS_MOUNT_DISCARD;
362+
} else if (!strcmp(this_char, MNTOPT_NODISCARD)) {
363+
mp->m_flags &= ~XFS_MOUNT_DISCARD;
358364
} else if (!strcmp(this_char, "ihashsize")) {
359365
xfs_warn(mp,
360366
"ihashsize no longer used, option is deprecated.");
@@ -388,6 +394,13 @@ xfs_parseargs(
388394
return EINVAL;
389395
}
390396

397+
if ((mp->m_flags & XFS_MOUNT_DISCARD) &&
398+
!(mp->m_flags & XFS_MOUNT_DELAYLOG)) {
399+
xfs_warn(mp,
400+
"the discard option is incompatible with the nodelaylog option");
401+
return EINVAL;
402+
}
403+
391404
#ifndef CONFIG_XFS_QUOTA
392405
if (XFS_IS_QUOTA_RUNNING(mp)) {
393406
xfs_warn(mp, "quota support not available in this kernel.");
@@ -488,6 +501,7 @@ xfs_showargs(
488501
{ XFS_MOUNT_FILESTREAMS, "," MNTOPT_FILESTREAM },
489502
{ XFS_MOUNT_GRPID, "," MNTOPT_GRPID },
490503
{ XFS_MOUNT_DELAYLOG, "," MNTOPT_DELAYLOG },
504+
{ XFS_MOUNT_DISCARD, "," MNTOPT_DISCARD },
491505
{ 0, NULL }
492506
};
493507
static struct proc_xfs_info xfs_info_unset[] = {

‎fs/xfs/xfs_ag.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ struct xfs_busy_extent {
187187
xfs_agnumber_t agno;
188188
xfs_agblock_t bno;
189189
xfs_extlen_t length;
190+
unsigned int flags;
191+
#define XFS_ALLOC_BUSY_DISCARDED 0x01 /* undergoing a discard op. */
192+
#define XFS_ALLOC_BUSY_SKIP_DISCARD 0x02 /* do not discard */
190193
};
191194

192195
/*

‎fs/xfs/xfs_alloc.c‎

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2469,7 +2469,7 @@ xfs_free_extent(
24692469

24702470
error = xfs_free_ag_extent(tp, args.agbp, args.agno, args.agbno, len, 0);
24712471
if (!error)
2472-
xfs_alloc_busy_insert(tp, args.agno, args.agbno, len);
2472+
xfs_alloc_busy_insert(tp, args.agno, args.agbno, len, 0);
24732473
error0:
24742474
xfs_perag_put(args.pag);
24752475
return error;
@@ -2480,7 +2480,8 @@ xfs_alloc_busy_insert(
24802480
struct xfs_trans *tp,
24812481
xfs_agnumber_t agno,
24822482
xfs_agblock_t bno,
2483-
xfs_extlen_t len)
2483+
xfs_extlen_t len,
2484+
unsigned int flags)
24842485
{
24852486
struct xfs_busy_extent *new;
24862487
struct xfs_busy_extent *busyp;
@@ -2504,6 +2505,7 @@ xfs_alloc_busy_insert(
25042505
new->bno = bno;
25052506
new->length = len;
25062507
INIT_LIST_HEAD(&new->list);
2508+
new->flags = flags;
25072509

25082510
/* trace before insert to be able to see failed inserts */
25092511
trace_xfs_alloc_busy(tp->t_mountp, agno, bno, len);
@@ -2608,6 +2610,18 @@ xfs_alloc_busy_update_extent(
26082610
xfs_agblock_t bbno = busyp->bno;
26092611
xfs_agblock_t bend = bbno + busyp->length;
26102612

2613+
/*
2614+
* This extent is currently being discarded. Give the thread
2615+
* performing the discard a chance to mark the extent unbusy
2616+
* and retry.
2617+
*/
2618+
if (busyp->flags & XFS_ALLOC_BUSY_DISCARDED) {
2619+
spin_unlock(&pag->pagb_lock);
2620+
delay(1);
2621+
spin_lock(&pag->pagb_lock);
2622+
return false;
2623+
}
2624+
26112625
/*
26122626
* If there is a busy extent overlapping a user allocation, we have
26132627
* no choice but to force the log and retry the search.
@@ -2813,7 +2827,8 @@ xfs_alloc_busy_trim(
28132827
* If this is a metadata allocation, try to reuse the busy
28142828
* extent instead of trimming the allocation.
28152829
*/
2816-
if (!args->userdata) {
2830+
if (!args->userdata &&
2831+
!(busyp->flags & XFS_ALLOC_BUSY_DISCARDED)) {
28172832
if (!xfs_alloc_busy_update_extent(args->mp, args->pag,
28182833
busyp, fbno, flen,
28192834
false))
@@ -2979,10 +2994,16 @@ xfs_alloc_busy_clear_one(
29792994
kmem_free(busyp);
29802995
}
29812996

2997+
/*
2998+
* Remove all extents on the passed in list from the busy extents tree.
2999+
* If do_discard is set skip extents that need to be discarded, and mark
3000+
* these as undergoing a discard operation instead.
3001+
*/
29823002
void
29833003
xfs_alloc_busy_clear(
29843004
struct xfs_mount *mp,
2985-
struct list_head *list)
3005+
struct list_head *list,
3006+
bool do_discard)
29863007
{
29873008
struct xfs_busy_extent *busyp, *n;
29883009
struct xfs_perag *pag = NULL;
@@ -2999,7 +3020,11 @@ xfs_alloc_busy_clear(
29993020
agno = busyp->agno;
30003021
}
30013022

3002-
xfs_alloc_busy_clear_one(mp, pag, busyp);
3023+
if (do_discard && busyp->length &&
3024+
!(busyp->flags & XFS_ALLOC_BUSY_SKIP_DISCARD))
3025+
busyp->flags = XFS_ALLOC_BUSY_DISCARDED;
3026+
else
3027+
xfs_alloc_busy_clear_one(mp, pag, busyp);
30033028
}
30043029

30053030
if (pag) {

‎fs/xfs/xfs_alloc.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,11 @@ xfs_alloc_longest_free_extent(struct xfs_mount *mp,
137137
#ifdef __KERNEL__
138138
void
139139
xfs_alloc_busy_insert(struct xfs_trans *tp, xfs_agnumber_t agno,
140-
xfs_agblock_t bno, xfs_extlen_t len);
140+
xfs_agblock_t bno, xfs_extlen_t len, unsigned int flags);
141141

142142
void
143-
xfs_alloc_busy_clear(struct xfs_mount *mp, struct list_head *list);
143+
xfs_alloc_busy_clear(struct xfs_mount *mp, struct list_head *list,
144+
bool do_discard);
144145

145146
int
146147
xfs_alloc_busy_search(struct xfs_mount *mp, xfs_agnumber_t agno,

‎fs/xfs/xfs_alloc_btree.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ xfs_allocbt_free_block(
120120
if (error)
121121
return error;
122122

123-
xfs_alloc_busy_insert(cur->bc_tp, be32_to_cpu(agf->agf_seqno), bno, 1);
123+
xfs_alloc_busy_insert(cur->bc_tp, be32_to_cpu(agf->agf_seqno), bno, 1,
124+
XFS_ALLOC_BUSY_SKIP_DISCARD);
124125
xfs_trans_agbtree_delta(cur->bc_tp, -1);
125126
return 0;
126127
}

0 commit comments

Comments
 (0)