Sat Apr 18 16:58:00 2020 UTC ()
make compile with XBD_DEBUG


(jdolecek)
diff -r1.118 -r1.119 src/sys/arch/xen/xen/xbd_xenbus.c

cvs diff -r1.118 -r1.119 src/sys/arch/xen/xen/xbd_xenbus.c (expand / switch to unified diff)

--- src/sys/arch/xen/xen/xbd_xenbus.c 2020/04/17 10:35:06 1.118
+++ src/sys/arch/xen/xen/xbd_xenbus.c 2020/04/18 16:58:00 1.119
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: xbd_xenbus.c,v 1.118 2020/04/17 10:35:06 jdolecek Exp $ */ 1/* $NetBSD: xbd_xenbus.c,v 1.119 2020/04/18 16:58:00 jdolecek Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2006 Manuel Bouyer. 4 * Copyright (c) 2006 Manuel Bouyer.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
@@ -40,27 +40,27 @@ @@ -40,27 +40,27 @@
40 * - initiate request: xbdread/write/open/ioctl/.. 40 * - initiate request: xbdread/write/open/ioctl/..
41 * - depending on operation, it is handled directly by disk(9) subsystem or 41 * - depending on operation, it is handled directly by disk(9) subsystem or
42 * goes through physio(9) first. 42 * goes through physio(9) first.
43 * - the request is ultimately processed by xbd_diskstart() that prepares the 43 * - the request is ultimately processed by xbd_diskstart() that prepares the
44 * xbd requests, post them in the ring I/O queue, then signal the backend. 44 * xbd requests, post them in the ring I/O queue, then signal the backend.
45 * 45 *
46 * When a response is available in the queue, the backend signals the frontend 46 * When a response is available in the queue, the backend signals the frontend
47 * via its event channel. This triggers xbd_handler(), which will link back 47 * via its event channel. This triggers xbd_handler(), which will link back
48 * the response to its request through the request ID, and mark the I/O as 48 * the response to its request through the request ID, and mark the I/O as
49 * completed. 49 * completed.
50 */ 50 */
51 51
52#include <sys/cdefs.h> 52#include <sys/cdefs.h>
53__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.118 2020/04/17 10:35:06 jdolecek Exp $"); 53__KERNEL_RCSID(0, "$NetBSD: xbd_xenbus.c,v 1.119 2020/04/18 16:58:00 jdolecek Exp $");
54 54
55#include "opt_xen.h" 55#include "opt_xen.h"
56 56
57 57
58#include <sys/param.h> 58#include <sys/param.h>
59#include <sys/buf.h> 59#include <sys/buf.h>
60#include <sys/bufq.h> 60#include <sys/bufq.h>
61#include <sys/device.h> 61#include <sys/device.h>
62#include <sys/disk.h> 62#include <sys/disk.h>
63#include <sys/disklabel.h> 63#include <sys/disklabel.h>
64#include <sys/conf.h> 64#include <sys/conf.h>
65#include <sys/fcntl.h> 65#include <sys/fcntl.h>
66#include <sys/kernel.h> 66#include <sys/kernel.h>
@@ -271,32 +271,26 @@ xbd_xenbus_match(device_t parent, cfdata @@ -271,32 +271,26 @@ xbd_xenbus_match(device_t parent, cfdata
271 match->cf_loc[XENBUSCF_ID] != xa->xa_id) 271 match->cf_loc[XENBUSCF_ID] != xa->xa_id)
272 return 0; 272 return 0;
273 273
274 return 1; 274 return 1;
275} 275}
276 276
277static void 277static void
278xbd_xenbus_attach(device_t parent, device_t self, void *aux) 278xbd_xenbus_attach(device_t parent, device_t self, void *aux)
279{ 279{
280 struct xbd_xenbus_softc *sc = device_private(self); 280 struct xbd_xenbus_softc *sc = device_private(self);
281 struct xenbusdev_attach_args *xa = aux; 281 struct xenbusdev_attach_args *xa = aux;
282 blkif_sring_t *ring; 282 blkif_sring_t *ring;
283 RING_IDX i; 283 RING_IDX i;
284#ifdef XBD_DEBUG 
285 char **dir, *val; 
286 int dir_n = 0; 
287 char id_str[20]; 
288 int err; 
289#endif 
290 284
291 config_pending_incr(self); 285 config_pending_incr(self);
292 aprint_normal(": Xen Virtual Block Device Interface\n"); 286 aprint_normal(": Xen Virtual Block Device Interface\n");
293 287
294 dk_init(&sc->sc_dksc, self, DKTYPE_ESDI); 288 dk_init(&sc->sc_dksc, self, DKTYPE_ESDI);
295 disk_init(&sc->sc_dksc.sc_dkdev, device_xname(self), &xbddkdriver); 289 disk_init(&sc->sc_dksc.sc_dkdev, device_xname(self), &xbddkdriver);
296 290
297 sc->sc_xbusd = xa->xa_xbusd; 291 sc->sc_xbusd = xa->xa_xbusd;
298 sc->sc_xbusd->xbusd_otherend_changed = xbd_backend_changed; 292 sc->sc_xbusd->xbusd_otherend_changed = xbd_backend_changed;
299 293
300 mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_BIO); 294 mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_BIO);
301 cv_init(&sc->sc_cache_flush_cv, "xbdsync"); 295 cv_init(&sc->sc_cache_flush_cv, "xbdsync");
302 cv_init(&sc->sc_req_cv, "xbdreq"); 296 cv_init(&sc->sc_req_cv, "xbdreq");
@@ -923,38 +917,38 @@ xbd_iosize(device_t dev, int *maxxfer) @@ -923,38 +917,38 @@ xbd_iosize(device_t dev, int *maxxfer)
923} 917}
924 918
925int 919int
926xbdopen(dev_t dev, int flags, int fmt, struct lwp *l) 920xbdopen(dev_t dev, int flags, int fmt, struct lwp *l)
927{ 921{
928 struct xbd_xenbus_softc *sc; 922 struct xbd_xenbus_softc *sc;
929 923
930 sc = device_lookup_private(&xbd_cd, DISKUNIT(dev)); 924 sc = device_lookup_private(&xbd_cd, DISKUNIT(dev));
931 if (sc == NULL) 925 if (sc == NULL)
932 return (ENXIO); 926 return (ENXIO);
933 if ((flags & FWRITE) && (sc->sc_info & VDISK_READONLY)) 927 if ((flags & FWRITE) && (sc->sc_info & VDISK_READONLY))
934 return EROFS; 928 return EROFS;
935 929
936 DPRINTF(("xbdopen(0x%04x, %d)\n", dev, flags)); 930 DPRINTF(("xbdopen(%" PRIx64 ", %d)\n", dev, flags));
937 return dk_open(&sc->sc_dksc, dev, flags, fmt, l); 931 return dk_open(&sc->sc_dksc, dev, flags, fmt, l);
938} 932}
939 933
940int 934int
941xbdclose(dev_t dev, int flags, int fmt, struct lwp *l) 935xbdclose(dev_t dev, int flags, int fmt, struct lwp *l)
942{ 936{
943 struct xbd_xenbus_softc *sc; 937 struct xbd_xenbus_softc *sc;
944 938
945 sc = device_lookup_private(&xbd_cd, DISKUNIT(dev)); 939 sc = device_lookup_private(&xbd_cd, DISKUNIT(dev));
946 940
947 DPRINTF(("xbdclose(%d, %d)\n", dev, flags)); 941 DPRINTF(("xbdclose(%" PRIx64 ", %d)\n", dev, flags));
948 return dk_close(&sc->sc_dksc, dev, flags, fmt, l); 942 return dk_close(&sc->sc_dksc, dev, flags, fmt, l);
949} 943}
950 944
951void 945void
952xbdstrategy(struct buf *bp) 946xbdstrategy(struct buf *bp)
953{ 947{
954 struct xbd_xenbus_softc *sc; 948 struct xbd_xenbus_softc *sc;
955 949
956 sc = device_lookup_private(&xbd_cd, DISKUNIT(bp->b_dev)); 950 sc = device_lookup_private(&xbd_cd, DISKUNIT(bp->b_dev));
957 951
958 DPRINTF(("xbdstrategy(%p): b_bcount = %ld\n", bp, 952 DPRINTF(("xbdstrategy(%p): b_bcount = %ld\n", bp,
959 (long)bp->b_bcount)); 953 (long)bp->b_bcount));
960 954
@@ -969,27 +963,27 @@ xbdstrategy(struct buf *bp) @@ -969,27 +963,27 @@ xbdstrategy(struct buf *bp)
969 biodone(bp); 963 biodone(bp);
970 return; 964 return;
971 } 965 }
972 966
973 dk_strategy(&sc->sc_dksc, bp); 967 dk_strategy(&sc->sc_dksc, bp);
974 return; 968 return;
975} 969}
976 970
977int 971int
978xbdsize(dev_t dev) 972xbdsize(dev_t dev)
979{ 973{
980 struct xbd_xenbus_softc *sc; 974 struct xbd_xenbus_softc *sc;
981 975
982 DPRINTF(("xbdsize(%d)\n", dev)); 976 DPRINTF(("xbdsize(%" PRIx64 ")\n", dev));
983 977
984 sc = device_lookup_private(&xbd_cd, DISKUNIT(dev)); 978 sc = device_lookup_private(&xbd_cd, DISKUNIT(dev));
985 if (sc == NULL || sc->sc_shutdown != BLKIF_SHUTDOWN_RUN) 979 if (sc == NULL || sc->sc_shutdown != BLKIF_SHUTDOWN_RUN)
986 return -1; 980 return -1;
987 return dk_size(&sc->sc_dksc, dev); 981 return dk_size(&sc->sc_dksc, dev);
988} 982}
989 983
990int 984int
991xbdread(dev_t dev, struct uio *uio, int flags) 985xbdread(dev_t dev, struct uio *uio, int flags)
992{ 986{
993 struct xbd_xenbus_softc *sc =  987 struct xbd_xenbus_softc *sc =
994 device_lookup_private(&xbd_cd, DISKUNIT(dev)); 988 device_lookup_private(&xbd_cd, DISKUNIT(dev));
995 struct dk_softc *dksc = &sc->sc_dksc; 989 struct dk_softc *dksc = &sc->sc_dksc;
@@ -1014,27 +1008,27 @@ xbdwrite(dev_t dev, struct uio *uio, int @@ -1014,27 +1008,27 @@ xbdwrite(dev_t dev, struct uio *uio, int
1014} 1008}
1015 1009
1016int 1010int
1017xbdioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l) 1011xbdioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
1018{ 1012{
1019 struct xbd_xenbus_softc *sc = 1013 struct xbd_xenbus_softc *sc =
1020 device_lookup_private(&xbd_cd, DISKUNIT(dev)); 1014 device_lookup_private(&xbd_cd, DISKUNIT(dev));
1021 struct dk_softc *dksc; 1015 struct dk_softc *dksc;
1022 int error; 1016 int error;
1023 struct xbd_req *xbdreq; 1017 struct xbd_req *xbdreq;
1024 blkif_request_t *req; 1018 blkif_request_t *req;
1025 int notify; 1019 int notify;
1026 1020
1027 DPRINTF(("xbdioctl(%d, %08lx, %p, %d, %p)\n", 1021 DPRINTF(("xbdioctl(%" PRIx64 ", %08lx, %p, %d, %p)\n",
1028 dev, cmd, data, flag, l)); 1022 dev, cmd, data, flag, l));
1029 dksc = &sc->sc_dksc; 1023 dksc = &sc->sc_dksc;
1030 1024
1031 switch (cmd) { 1025 switch (cmd) {
1032 case DIOCGCACHE: 1026 case DIOCGCACHE:
1033 { 1027 {
1034 /* Assume there is write cache if cache-flush is supported */ 1028 /* Assume there is write cache if cache-flush is supported */
1035 int *bitsp = (int *)data; 1029 int *bitsp = (int *)data;
1036 *bitsp = 0; 1030 *bitsp = 0;
1037 if (sc->sc_features & BLKIF_FEATURE_CACHE_FLUSH) 1031 if (sc->sc_features & BLKIF_FEATURE_CACHE_FLUSH)
1038 *bitsp |= DKCACHE_WRITE; 1032 *bitsp |= DKCACHE_WRITE;
1039 error = 0; 1033 error = 0;
1040 break; 1034 break;
@@ -1083,27 +1077,27 @@ xbdioctl(dev_t dev, u_long cmd, void *da @@ -1083,27 +1077,27 @@ xbdioctl(dev_t dev, u_long cmd, void *da
1083 1077
1084 return error; 1078 return error;
1085} 1079}
1086 1080
1087int 1081int
1088xbddump(dev_t dev, daddr_t blkno, void *va, size_t size) 1082xbddump(dev_t dev, daddr_t blkno, void *va, size_t size)
1089{ 1083{
1090 struct xbd_xenbus_softc *sc; 1084 struct xbd_xenbus_softc *sc;
1091 1085
1092 sc = device_lookup_private(&xbd_cd, DISKUNIT(dev)); 1086 sc = device_lookup_private(&xbd_cd, DISKUNIT(dev));
1093 if (sc == NULL) 1087 if (sc == NULL)
1094 return (ENXIO); 1088 return (ENXIO);
1095 1089
1096 DPRINTF(("xbddump(%d, %" PRId64 ", %p, %lu)\n", dev, blkno, va, 1090 DPRINTF(("xbddump(%" PRIx64 ", %" PRId64 ", %p, %lu)\n", dev, blkno, va,
1097 (unsigned long)size)); 1091 (unsigned long)size));
1098 return dk_dump(&sc->sc_dksc, dev, blkno, va, size, 0); 1092 return dk_dump(&sc->sc_dksc, dev, blkno, va, size, 0);
1099} 1093}
1100 1094
1101static int 1095static int
1102xbd_diskstart(device_t self, struct buf *bp) 1096xbd_diskstart(device_t self, struct buf *bp)
1103{ 1097{
1104 struct xbd_xenbus_softc *sc = device_private(self); 1098 struct xbd_xenbus_softc *sc = device_private(self);
1105 struct xbd_req *xbdreq; 1099 struct xbd_req *xbdreq;
1106 int error = 0; 1100 int error = 0;
1107 int notify; 1101 int notify;
1108 1102
1109 KASSERT(bp->b_bcount <= MAXPHYS); 1103 KASSERT(bp->b_bcount <= MAXPHYS);