Sat Sep 24 23:18:54 2022 UTC ()
malloc(9) -> kmem(9)


(thorpej)
diff -r1.112 -r1.113 src/sys/dev/fss.c

cvs diff -r1.112 -r1.113 src/sys/dev/fss.c (expand / switch to unified diff)

--- src/sys/dev/fss.c 2022/03/31 19:30:15 1.112
+++ src/sys/dev/fss.c 2022/09/24 23:18:54 1.113
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: fss.c,v 1.112 2022/03/31 19:30:15 pgoyette Exp $ */ 1/* $NetBSD: fss.c,v 1.113 2022/09/24 23:18:54 thorpej Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2003 The NetBSD Foundation, Inc. 4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Juergen Hannken-Illjes. 8 * by Juergen Hannken-Illjes.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -26,34 +26,34 @@ @@ -26,34 +26,34 @@
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32/* 32/*
33 * File system snapshot disk driver. 33 * File system snapshot disk driver.
34 * 34 *
35 * Block/character interface to the snapshot of a mounted file system. 35 * Block/character interface to the snapshot of a mounted file system.
36 */ 36 */
37 37
38#include <sys/cdefs.h> 38#include <sys/cdefs.h>
39__KERNEL_RCSID(0, "$NetBSD: fss.c,v 1.112 2022/03/31 19:30:15 pgoyette Exp $"); 39__KERNEL_RCSID(0, "$NetBSD: fss.c,v 1.113 2022/09/24 23:18:54 thorpej Exp $");
40 40
41#include <sys/param.h> 41#include <sys/param.h>
42#include <sys/systm.h> 42#include <sys/systm.h>
43#include <sys/namei.h> 43#include <sys/namei.h>
44#include <sys/proc.h> 44#include <sys/proc.h>
45#include <sys/errno.h> 45#include <sys/errno.h>
46#include <sys/malloc.h> 46#include <sys/kmem.h>
47#include <sys/buf.h> 47#include <sys/buf.h>
48#include <sys/ioctl.h> 48#include <sys/ioctl.h>
49#include <sys/disklabel.h> 49#include <sys/disklabel.h>
50#include <sys/device.h> 50#include <sys/device.h>
51#include <sys/disk.h> 51#include <sys/disk.h>
52#include <sys/stat.h> 52#include <sys/stat.h>
53#include <sys/mount.h> 53#include <sys/mount.h>
54#include <sys/vnode.h> 54#include <sys/vnode.h>
55#include <sys/file.h> 55#include <sys/file.h>
56#include <sys/uio.h> 56#include <sys/uio.h>
57#include <sys/conf.h> 57#include <sys/conf.h>
58#include <sys/kthread.h> 58#include <sys/kthread.h>
59#include <sys/fstrans.h> 59#include <sys/fstrans.h>
@@ -150,27 +150,27 @@ fss_match(device_t self, cfdata_t cfdata @@ -150,27 +150,27 @@ fss_match(device_t self, cfdata_t cfdata
150} 150}
151 151
152static void 152static void
153fss_attach(device_t parent, device_t self, void *aux) 153fss_attach(device_t parent, device_t self, void *aux)
154{ 154{
155 struct fss_softc *sc = device_private(self); 155 struct fss_softc *sc = device_private(self);
156 156
157 sc->sc_dev = self; 157 sc->sc_dev = self;
158 sc->sc_bdev = NODEV; 158 sc->sc_bdev = NODEV;
159 mutex_init(&sc->sc_slock, MUTEX_DEFAULT, IPL_NONE); 159 mutex_init(&sc->sc_slock, MUTEX_DEFAULT, IPL_NONE);
160 cv_init(&sc->sc_work_cv, "fssbs"); 160 cv_init(&sc->sc_work_cv, "fssbs");
161 cv_init(&sc->sc_cache_cv, "cowwait"); 161 cv_init(&sc->sc_cache_cv, "cowwait");
162 bufq_alloc(&sc->sc_bufq, "fcfs", 0); 162 bufq_alloc(&sc->sc_bufq, "fcfs", 0);
163 sc->sc_dkdev = malloc(sizeof(*sc->sc_dkdev), M_DEVBUF, M_WAITOK); 163 sc->sc_dkdev = kmem_zalloc(sizeof(*sc->sc_dkdev), KM_SLEEP);
164 sc->sc_dkdev->dk_info = NULL; 164 sc->sc_dkdev->dk_info = NULL;
165 disk_init(sc->sc_dkdev, device_xname(self), NULL); 165 disk_init(sc->sc_dkdev, device_xname(self), NULL);
166 if (!pmf_device_register(self, NULL, NULL)) 166 if (!pmf_device_register(self, NULL, NULL))
167 aprint_error_dev(self, "couldn't establish power handler\n"); 167 aprint_error_dev(self, "couldn't establish power handler\n");
168 168
169 if (fss_num_attached++ == 0) 169 if (fss_num_attached++ == 0)
170 vfs_hooks_attach(&fss_vfs_hooks); 170 vfs_hooks_attach(&fss_vfs_hooks);
171} 171}
172 172
173static int 173static int
174fss_detach(device_t self, int flags) 174fss_detach(device_t self, int flags)
175{ 175{
176 struct fss_softc *sc = device_private(self); 176 struct fss_softc *sc = device_private(self);
@@ -182,45 +182,45 @@ fss_detach(device_t self, int flags) @@ -182,45 +182,45 @@ fss_detach(device_t self, int flags)
182 } 182 }
183 mutex_exit(&sc->sc_slock); 183 mutex_exit(&sc->sc_slock);
184 184
185 if (--fss_num_attached == 0) 185 if (--fss_num_attached == 0)
186 vfs_hooks_detach(&fss_vfs_hooks); 186 vfs_hooks_detach(&fss_vfs_hooks);
187 187
188 pmf_device_deregister(self); 188 pmf_device_deregister(self);
189 mutex_destroy(&sc->sc_slock); 189 mutex_destroy(&sc->sc_slock);
190 cv_destroy(&sc->sc_work_cv); 190 cv_destroy(&sc->sc_work_cv);
191 cv_destroy(&sc->sc_cache_cv); 191 cv_destroy(&sc->sc_cache_cv);
192 bufq_drain(sc->sc_bufq); 192 bufq_drain(sc->sc_bufq);
193 bufq_free(sc->sc_bufq); 193 bufq_free(sc->sc_bufq);
194 disk_destroy(sc->sc_dkdev); 194 disk_destroy(sc->sc_dkdev);
195 free(sc->sc_dkdev, M_DEVBUF); 195 kmem_free(sc->sc_dkdev, sizeof(*sc->sc_dkdev));
196 196
197 return 0; 197 return 0;
198} 198}
199 199
200int 200int
201fss_open(dev_t dev, int flags, int mode, struct lwp *l) 201fss_open(dev_t dev, int flags, int mode, struct lwp *l)
202{ 202{
203 int mflag; 203 int mflag;
204 cfdata_t cf; 204 cfdata_t cf;
205 struct fss_softc *sc; 205 struct fss_softc *sc;
206 206
207 mflag = (mode == S_IFCHR ? FSS_CDEV_OPEN : FSS_BDEV_OPEN); 207 mflag = (mode == S_IFCHR ? FSS_CDEV_OPEN : FSS_BDEV_OPEN);
208 208
209 mutex_enter(&fss_device_lock); 209 mutex_enter(&fss_device_lock);
210 210
211 sc = device_lookup_private(&fss_cd, minor(dev)); 211 sc = device_lookup_private(&fss_cd, minor(dev));
212 if (sc == NULL) { 212 if (sc == NULL) {
213 cf = malloc(sizeof(*cf), M_DEVBUF, M_WAITOK); 213 cf = kmem_zalloc(sizeof(*cf), KM_SLEEP);
214 cf->cf_name = fss_cd.cd_name; 214 cf->cf_name = fss_cd.cd_name;
215 cf->cf_atname = fss_cd.cd_name; 215 cf->cf_atname = fss_cd.cd_name;
216 cf->cf_unit = minor(dev); 216 cf->cf_unit = minor(dev);
217 cf->cf_fstate = FSTATE_STAR; 217 cf->cf_fstate = FSTATE_STAR;
218 sc = device_private(config_attach_pseudo(cf)); 218 sc = device_private(config_attach_pseudo(cf));
219 if (sc == NULL) { 219 if (sc == NULL) {
220 mutex_exit(&fss_device_lock); 220 mutex_exit(&fss_device_lock);
221 return ENOMEM; 221 return ENOMEM;
222 } 222 }
223 sc->sc_state = FSS_IDLE; 223 sc->sc_state = FSS_IDLE;
224 } 224 }
225 225
226 mutex_enter(&sc->sc_slock); 226 mutex_enter(&sc->sc_slock);
@@ -264,27 +264,27 @@ restart: @@ -264,27 +264,27 @@ restart:
264 } 264 }
265 if (sc->sc_state != FSS_IDLE) { 265 if (sc->sc_state != FSS_IDLE) {
266 mutex_exit(&sc->sc_slock); 266 mutex_exit(&sc->sc_slock);
267 mutex_exit(&fss_device_lock); 267 mutex_exit(&fss_device_lock);
268 return error; 268 return error;
269 } 269 }
270 270
271 KASSERT(sc->sc_state == FSS_IDLE); 271 KASSERT(sc->sc_state == FSS_IDLE);
272 KASSERT((sc->sc_flags & (FSS_CDEV_OPEN|FSS_BDEV_OPEN)) == mflag); 272 KASSERT((sc->sc_flags & (FSS_CDEV_OPEN|FSS_BDEV_OPEN)) == mflag);
273 mutex_exit(&sc->sc_slock); 273 mutex_exit(&sc->sc_slock);
274 cf = device_cfdata(sc->sc_dev); 274 cf = device_cfdata(sc->sc_dev);
275 error = config_detach(sc->sc_dev, DETACH_QUIET); 275 error = config_detach(sc->sc_dev, DETACH_QUIET);
276 if (! error) 276 if (! error)
277 free(cf, M_DEVBUF); 277 kmem_free(cf, sizeof(*cf));
278 mutex_exit(&fss_device_lock); 278 mutex_exit(&fss_device_lock);
279 279
280 return error; 280 return error;
281} 281}
282 282
283void 283void
284fss_strategy(struct buf *bp) 284fss_strategy(struct buf *bp)
285{ 285{
286 const bool write = ((bp->b_flags & B_READ) != B_READ); 286 const bool write = ((bp->b_flags & B_READ) != B_READ);
287 struct fss_softc *sc = device_lookup_private(&fss_cd, minor(bp->b_dev)); 287 struct fss_softc *sc = device_lookup_private(&fss_cd, minor(bp->b_dev));
288 288
289 if (sc == NULL) { 289 if (sc == NULL) {
290 bp->b_error = ENXIO; 290 bp->b_error = ENXIO;