Skip to contentSkip to conversation

xfs: check if device support discard in xfs_ioc_trim()

PATCH In review Lukas Czerner 2 participants 2 messages Feb 15, 2011 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: check if device support discard in xfs_ioc_trim()

Right now we, are relying on the fact that when we attempt to actually do the discard, blkdev_issue_discar() returns -EOPNOTSUPP and the user is informed that the device does not support discard.

However, in the case where the we do not hit any suitable free extent to trim in FITRIM code, it will finish without any error. This is very confusing, because it seems that FITRIM was successful even though the device does not actually supports discard.

Solution: Check for the discard support before attempt to search for free extents.

---
 fs/xfs/linux-2.6/xfs_discard.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
fs/xfs/linux-2.6/xfs_discard.c +2 -0
index 05201ae..d61611c 100644
@@ -152,6 +152,8 @@ xfs_ioc_trim(
 
 	if (!capable(CAP_SYS_ADMIN))
 		return -XFS_ERROR(EPERM);
+	if (!blk_queue_discard(q))
+		return -XFS_ERROR(EOPNOTSUPP);
 	if (copy_from_user(&range, urange, sizeof(range)))
 		return -XFS_ERROR(EFAULT);
 
Signature · 6 lines
1.7.4

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Reviewed-by on v1 1/1
#1 lore raw
Quoted 22 lines · Lukas Czerner

Right now we, are relying on the fact that when we attempt to actually do the discard, blkdev_issue_discar() returns -EOPNOTSUPP and the user is informed that the device does not support discard.

However, in the case where the we do not hit any suitable free extent to trim in FITRIM code, it will finish without any error. This is very confusing, because it seems that FITRIM was successful even though the device does not actually supports discard.

Solution: Check for the discard support before attempt to search for free extents.

---
 fs/xfs/linux-2.6/xfs_discard.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
fs/xfs/linux-2.6/xfs_discard.c +0 -0
index 05201ae..d61611c 100644

fs/xfs/linux-2.6/xfs_discard.c xfs_ioc_trim( · line 159

Quoted 8 lines
fs/xfs/linux-2.6/xfs_discard.c +2 -0
@@ -152,6 +152,8 @@ xfs_ioc_trim(
 
 	if (!capable(CAP_SYS_ADMIN))
 		return -XFS_ERROR(EPERM);
+	if (!blk_queue_discard(q))
+		return -XFS_ERROR(EOPNOTSUPP);
 	if (copy_from_user(&range, urange, sizeof(range)))
 		return -XFS_ERROR(EFAULT);
 

Looks good.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs