Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-doc
Path: blob/main/website/static/security/patches/EN-15:05/ufs.patch
18096 views
1
Index: sys/ufs/ffs/ffs_softdep.c
2
===================================================================
3
--- sys/ufs/ffs/ffs_softdep.c (revision 282245)
4
+++ sys/ufs/ffs/ffs_softdep.c (working copy)
5
@@ -735,9 +735,10 @@ static struct malloc_type *memtype[] = {
6
static void check_clear_deps(struct mount *);
7
static void softdep_error(char *, int);
8
static int softdep_process_worklist(struct mount *, int);
9
-static int softdep_waitidle(struct mount *);
10
+static int softdep_waitidle(struct mount *, int);
11
static void drain_output(struct vnode *);
12
static struct buf *getdirtybuf(struct buf *, struct rwlock *, int);
13
+static int check_inodedep_free(struct inodedep *);
14
static void clear_remove(struct mount *);
15
static void clear_inodedeps(struct mount *);
16
static void unlinked_inodedep(struct mount *, struct inodedep *);
17
@@ -1377,6 +1378,10 @@ softdep_flush(addr)
18
mp = (struct mount *)addr;
19
ump = VFSTOUFS(mp);
20
atomic_add_int(&stat_flush_threads, 1);
21
+ ACQUIRE_LOCK(ump);
22
+ ump->softdep_flags &= ~FLUSH_STARTING;
23
+ wakeup(&ump->softdep_flushtd);
24
+ FREE_LOCK(ump);
25
if (print_threads) {
26
if (stat_flush_threads == 1)
27
printf("Running %s at pid %d\n", bufdaemonproc->p_comm,
28
@@ -1389,7 +1394,7 @@ softdep_flush(addr)
29
VFSTOUFS(mp)->softdep_jblocks->jb_suspended))
30
kthread_suspend_check();
31
ACQUIRE_LOCK(ump);
32
- if ((ump->softdep_flags & FLUSH_CLEANUP) == 0)
33
+ if ((ump->softdep_flags & (FLUSH_CLEANUP | FLUSH_EXIT)) == 0)
34
msleep(&ump->softdep_flushtd, LOCK_PTR(ump), PVM,
35
"sdflush", hz / 2);
36
ump->softdep_flags &= ~FLUSH_CLEANUP;
37
@@ -1419,11 +1424,9 @@ worklist_speedup(mp)
38
39
ump = VFSTOUFS(mp);
40
LOCK_OWNED(ump);
41
- if ((ump->softdep_flags & (FLUSH_CLEANUP | FLUSH_EXIT)) == 0) {
42
+ if ((ump->softdep_flags & (FLUSH_CLEANUP | FLUSH_EXIT)) == 0)
43
ump->softdep_flags |= FLUSH_CLEANUP;
44
- if (ump->softdep_flushtd->td_wchan == &ump->softdep_flushtd)
45
- wakeup(&ump->softdep_flushtd);
46
- }
47
+ wakeup(&ump->softdep_flushtd);
48
}
49
50
static int
51
@@ -1468,14 +1471,10 @@ softdep_speedup(ump)
52
TAILQ_INSERT_TAIL(&softdepmounts, sdp, sd_next);
53
FREE_GBLLOCK(&lk);
54
if ((altump->softdep_flags &
55
- (FLUSH_CLEANUP | FLUSH_EXIT)) == 0) {
56
+ (FLUSH_CLEANUP | FLUSH_EXIT)) == 0)
57
altump->softdep_flags |= FLUSH_CLEANUP;
58
- altump->um_softdep->sd_cleanups++;
59
- if (altump->softdep_flushtd->td_wchan ==
60
- &altump->softdep_flushtd) {
61
- wakeup(&altump->softdep_flushtd);
62
- }
63
- }
64
+ altump->um_softdep->sd_cleanups++;
65
+ wakeup(&altump->softdep_flushtd);
66
FREE_LOCK(altump);
67
}
68
}
69
@@ -1887,8 +1886,8 @@ softdep_flushworklist(oldmnt, countp, td
70
struct thread *td;
71
{
72
struct vnode *devvp;
73
- int count, error = 0;
74
struct ufsmount *ump;
75
+ int count, error;
76
77
/*
78
* Alternately flush the block device associated with the mount
79
@@ -1897,6 +1896,7 @@ softdep_flushworklist(oldmnt, countp, td
80
* are found.
81
*/
82
*countp = 0;
83
+ error = 0;
84
ump = VFSTOUFS(oldmnt);
85
devvp = ump->um_devvp;
86
while ((count = softdep_process_worklist(oldmnt, 1)) > 0) {
87
@@ -1904,36 +1904,47 @@ softdep_flushworklist(oldmnt, countp, td
88
vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
89
error = VOP_FSYNC(devvp, MNT_WAIT, td);
90
VOP_UNLOCK(devvp, 0);
91
- if (error)
92
+ if (error != 0)
93
break;
94
}
95
return (error);
96
}
97
98
+#define SU_WAITIDLE_RETRIES 20
99
static int
100
-softdep_waitidle(struct mount *mp)
101
+softdep_waitidle(struct mount *mp, int flags __unused)
102
{
103
struct ufsmount *ump;
104
- int error;
105
- int i;
106
+ struct vnode *devvp;
107
+ struct thread *td;
108
+ int error, i;
109
110
ump = VFSTOUFS(mp);
111
+ devvp = ump->um_devvp;
112
+ td = curthread;
113
+ error = 0;
114
ACQUIRE_LOCK(ump);
115
- for (i = 0; i < 10 && ump->softdep_deps; i++) {
116
+ for (i = 0; i < SU_WAITIDLE_RETRIES && ump->softdep_deps != 0; i++) {
117
ump->softdep_req = 1;
118
- if (ump->softdep_on_worklist)
119
- panic("softdep_waitidle: work added after flush.");
120
- msleep(&ump->softdep_deps, LOCK_PTR(ump), PVM, "softdeps", 1);
121
+ KASSERT((flags & FORCECLOSE) == 0 ||
122
+ ump->softdep_on_worklist == 0,
123
+ ("softdep_waitidle: work added after flush"));
124
+ msleep(&ump->softdep_deps, LOCK_PTR(ump), PVM | PDROP,
125
+ "softdeps", 10 * hz);
126
+ vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
127
+ error = VOP_FSYNC(devvp, MNT_WAIT, td);
128
+ VOP_UNLOCK(devvp, 0);
129
+ if (error != 0)
130
+ break;
131
+ ACQUIRE_LOCK(ump);
132
}
133
ump->softdep_req = 0;
134
- FREE_LOCK(ump);
135
- error = 0;
136
- if (i == 10) {
137
+ if (i == SU_WAITIDLE_RETRIES && error == 0 && ump->softdep_deps != 0) {
138
error = EBUSY;
139
printf("softdep_waitidle: Failed to flush worklist for %p\n",
140
mp);
141
}
142
-
143
+ FREE_LOCK(ump);
144
return (error);
145
}
146
147
@@ -1990,7 +2001,7 @@ retry_flush:
148
error = EBUSY;
149
}
150
if (!error)
151
- error = softdep_waitidle(oldmnt);
152
+ error = softdep_waitidle(oldmnt, flags);
153
if (!error) {
154
if (oldmnt->mnt_kern_flag & MNTK_UNMOUNT) {
155
retry = 0;
156
@@ -2490,9 +2501,18 @@ softdep_mount(devvp, mp, fs, cred)
157
/*
158
* Start our flushing thread in the bufdaemon process.
159
*/
160
+ ACQUIRE_LOCK(ump);
161
+ ump->softdep_flags |= FLUSH_STARTING;
162
+ FREE_LOCK(ump);
163
kproc_kthread_add(&softdep_flush, mp, &bufdaemonproc,
164
&ump->softdep_flushtd, 0, 0, "softdepflush", "%s worker",
165
mp->mnt_stat.f_mntonname);
166
+ ACQUIRE_LOCK(ump);
167
+ while ((ump->softdep_flags & FLUSH_STARTING) != 0) {
168
+ msleep(&ump->softdep_flushtd, LOCK_PTR(ump), PVM, "sdstart",
169
+ hz / 2);
170
+ }
171
+ FREE_LOCK(ump);
172
/*
173
* When doing soft updates, the counters in the
174
* superblock may have gotten out of sync. Recomputation
175
@@ -7629,17 +7649,13 @@ check_inode_unwritten(inodedep)
176
return (1);
177
}
178
179
-/*
180
- * Try to free an inodedep structure. Return 1 if it could be freed.
181
- */
182
static int
183
-free_inodedep(inodedep)
184
+check_inodedep_free(inodedep)
185
struct inodedep *inodedep;
186
{
187
188
LOCK_OWNED(VFSTOUFS(inodedep->id_list.wk_mp));
189
- if ((inodedep->id_state & (ONWORKLIST | UNLINKED)) != 0 ||
190
- (inodedep->id_state & ALLCOMPLETE) != ALLCOMPLETE ||
191
+ if ((inodedep->id_state & ALLCOMPLETE) != ALLCOMPLETE ||
192
!LIST_EMPTY(&inodedep->id_dirremhd) ||
193
!LIST_EMPTY(&inodedep->id_pendinghd) ||
194
!LIST_EMPTY(&inodedep->id_bufwait) ||
195
@@ -7654,6 +7670,21 @@ free_inodedep(inodedep)
196
inodedep->id_nlinkdelta != 0 ||
197
inodedep->id_savedino1 != NULL)
198
return (0);
199
+ return (1);
200
+}
201
+
202
+/*
203
+ * Try to free an inodedep structure. Return 1 if it could be freed.
204
+ */
205
+static int
206
+free_inodedep(inodedep)
207
+ struct inodedep *inodedep;
208
+{
209
+
210
+ LOCK_OWNED(VFSTOUFS(inodedep->id_list.wk_mp));
211
+ if ((inodedep->id_state & (ONWORKLIST | UNLINKED)) != 0 ||
212
+ !check_inodedep_free(inodedep))
213
+ return (0);
214
if (inodedep->id_state & ONDEPLIST)
215
LIST_REMOVE(inodedep, id_deps);
216
LIST_REMOVE(inodedep, id_hash);
217
@@ -13838,7 +13869,8 @@ softdep_check_suspend(struct mount *mp,
218
{
219
struct bufobj *bo;
220
struct ufsmount *ump;
221
- int error;
222
+ struct inodedep *inodedep;
223
+ int error, unlinked;
224
225
bo = &devvp->v_bufobj;
226
ASSERT_BO_WLOCKED(bo);
227
@@ -13899,6 +13931,20 @@ softdep_check_suspend(struct mount *mp,
228
break;
229
}
230
231
+ unlinked = 0;
232
+ if (MOUNTEDSUJ(mp)) {
233
+ for (inodedep = TAILQ_FIRST(&ump->softdep_unlinked);
234
+ inodedep != NULL;
235
+ inodedep = TAILQ_NEXT(inodedep, id_unlinked)) {
236
+ if ((inodedep->id_state & (UNLINKED | UNLINKLINKS |
237
+ UNLINKONLIST)) != (UNLINKED | UNLINKLINKS |
238
+ UNLINKONLIST) ||
239
+ !check_inodedep_free(inodedep))
240
+ continue;
241
+ unlinked++;
242
+ }
243
+ }
244
+
245
/*
246
* Reasons for needing more work before suspend:
247
* - Dirty buffers on devvp.
248
@@ -13908,8 +13954,8 @@ softdep_check_suspend(struct mount *mp,
249
error = 0;
250
if (bo->bo_numoutput > 0 ||
251
bo->bo_dirty.bv_cnt > 0 ||
252
- softdep_depcnt != 0 ||
253
- ump->softdep_deps != 0 ||
254
+ softdep_depcnt != unlinked ||
255
+ ump->softdep_deps != unlinked ||
256
softdep_accdepcnt != ump->softdep_accdeps ||
257
secondary_writes != 0 ||
258
mp->mnt_secondary_writes != 0 ||
259
Index: sys/ufs/ffs/ffs_vfsops.c
260
===================================================================
261
--- sys/ufs/ffs/ffs_vfsops.c (revision 282245)
262
+++ sys/ufs/ffs/ffs_vfsops.c (working copy)
263
@@ -1502,8 +1502,11 @@ ffs_sync(mp, waitfor)
264
if (fs->fs_fmod != 0 && fs->fs_ronly != 0 && ump->um_fsckpid == 0)
265
panic("%s: ffs_sync: modification on read-only filesystem",
266
fs->fs_fsmnt);
267
- if (waitfor == MNT_LAZY)
268
- return (ffs_sync_lazy(mp));
269
+ if (waitfor == MNT_LAZY) {
270
+ if (!rebooting)
271
+ return (ffs_sync_lazy(mp));
272
+ waitfor = MNT_NOWAIT;
273
+ }
274
275
/*
276
* Write back each (modified) inode.
277
@@ -1560,7 +1563,7 @@ loop:
278
/*
279
* Force stale filesystem control information to be flushed.
280
*/
281
- if (waitfor == MNT_WAIT) {
282
+ if (waitfor == MNT_WAIT || rebooting) {
283
if ((error = softdep_flushworklist(ump->um_mountp, &count, td)))
284
allerror = error;
285
/* Flushed work items may create new vnodes to clean */
286
@@ -1577,9 +1580,12 @@ loop:
287
if (bo->bo_numoutput > 0 || bo->bo_dirty.bv_cnt > 0) {
288
BO_UNLOCK(bo);
289
vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
290
- if ((error = VOP_FSYNC(devvp, waitfor, td)) != 0)
291
- allerror = error;
292
+ error = VOP_FSYNC(devvp, waitfor, td);
293
VOP_UNLOCK(devvp, 0);
294
+ if (MOUNTEDSOFTDEP(mp) && (error == 0 || error == EAGAIN))
295
+ error = ffs_sbupdate(ump, waitfor, 0);
296
+ if (error != 0)
297
+ allerror = error;
298
if (allerror == 0 && waitfor == MNT_WAIT)
299
goto loop;
300
} else if (suspend != 0) {
301
Index: sys/ufs/ffs/softdep.h
302
===================================================================
303
--- sys/ufs/ffs/softdep.h (revision 282245)
304
+++ sys/ufs/ffs/softdep.h (working copy)
305
@@ -1063,6 +1063,8 @@ struct mount_softdeps {
306
*/
307
#define FLUSH_EXIT 0x0001 /* time to exit */
308
#define FLUSH_CLEANUP 0x0002 /* need to clear out softdep structures */
309
+#define FLUSH_STARTING 0x0004 /* flush thread not yet started */
310
+
311
/*
312
* Keep the old names from when these were in the ufsmount structure.
313
*/
314
315