TRIM patch

Link to this paste: http://bugs.dragonflybsd.org/pastes/418

Added by about 2 years ago.
Syntax: C

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
From 851b59a7ab96dd483b9e7982dcd46c2efb44b921 Mon Sep 17 00:00:00 2001
From: Tim Bisson <bissont@mac.com>
Date: Fri, 12 Oct 2012 09:14:18 -0700
Subject: [PATCH] Fix TRIM: * Only enable TRIM if DRAT (Deterministic Read
 After TRIM) is supported * if trim is on as a option,
 display that when typing "mount" * make sure TRIM occurs
 with UFS when it is enabled. using  
 ip->i_devvp->v_mount->mnt_flag doesn't have mount options *
 change post trim ffs_blkfree_cg() to use taskqueue_swi_mp
 and get mp   token when modifying freemapw

---
 sys/dev/disk/ahci/ahci_cam.c |    3 ++-
 sys/kern/vfs_subr.c          |    1 +
 sys/vfs/ufs/ffs_alloc.c      |    6 ++++--
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/sys/dev/disk/ahci/ahci_cam.c b/sys/dev/disk/ahci/ahci_cam.c
index 3b5d857..f0a41fa 100644
--- a/sys/dev/disk/ahci/ahci_cam.c
+++ b/sys/dev/disk/ahci/ahci_cam.c
@@ -1095,7 +1095,8 @@ ahci_xpt_scsi_disk_io(struct ahci_port *ap, struct ata_port *atx,
                  */
                 if (at->at_identify.support_dsm) {
                         rdata->inquiry_data.vendor_specific1[0] =
-                            at->at_identify.support_dsm &ATA_SUPPORT_DSM_TRIM;
+                            (at->at_identify.support_dsm & ATA_SUPPORT_DSM_TRIM) &&
+                            (at->at_identify.support3 & ATA_SUPPORT_DRAT);
                         rdata->inquiry_data.vendor_specific1[1] = 
                             at->at_identify.max_dsm_blocks;
                 }
diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
index e6a0024..a3b2035 100644
--- a/sys/kern/vfs_subr.c
+++ b/sys/kern/vfs_subr.c
@@ -1835,6 +1835,7 @@ vfs_flagstostr(int flags, const struct mountctl_opt *optp,
                 { MNT_SUIDDIR,          "suiddir" },
                 { MNT_SOFTDEP,          "soft-updates" },
                 { MNT_IGNORE,           "ignore" },
+                { MNT_TRIM,             "trim" },
                 { 0,                        NULL}
         };
         int bwritten;
diff --git a/sys/vfs/ufs/ffs_alloc.c b/sys/vfs/ufs/ffs_alloc.c
index afcde72..9a26f1a 100644
--- a/sys/vfs/ufs/ffs_alloc.c
+++ b/sys/vfs/ufs/ffs_alloc.c
@@ -1627,8 +1627,10 @@ ffs_blkfree_trim_task(void *ctx, int pending)
         struct ffs_blkfree_trim_params *tp;
 
         tp = ctx;
+        lwkt_gettoken(&tp->i_devvp->v_mount->mnt_token);
         ffs_blkfree_cg(tp->i_fs, tp->i_devvp, tp->i_dev, tp->i_number,
             tp->i_din_uid, tp->bno, tp->size);
+        lwkt_reltoken(&tp->i_devvp->v_mount->mnt_token);
         kfree(tp, M_TEMP);
 }
 
@@ -1643,7 +1645,7 @@ ffs_blkfree_trim_completed(struct bio *biop)
         tp = bp->b_bio1.bio_caller_info1.ptr;
         TASK_INIT(&tp->task, 0, ffs_blkfree_trim_task, tp);
         tp = biop->bio_caller_info1.ptr;
-        taskqueue_enqueue(taskqueue_swi, &tp->task);
+        taskqueue_enqueue(taskqueue_swi_mp, &tp->task);
         biodone(biop);
 }
 
@@ -1658,7 +1660,7 @@ ffs_blkfree_trim_completed(struct bio *biop)
 void
 ffs_blkfree(struct inode *ip, ufs_daddr_t bno, long size) 
 {
-        struct mount *mp = ip->i_devvp->v_mount;
+        struct mount *mp = ip->i_vnode->v_mount;
         struct ffs_blkfree_trim_params *tp;
 
         if (!(mp->mnt_flag & MNT_TRIM)) {
-- 
1.7.5.4

Download