Deleted Added
full compact
g_eli_privacy.c (214116) g_eli_privacy.c (214118)
1/*-
2 * Copyright (c) 2005-2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2005-2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/geom/eli/g_eli_privacy.c 214116 2010-10-20 20:01:45Z pjd $");
28__FBSDID("$FreeBSD: head/sys/geom/eli/g_eli_privacy.c 214118 2010-10-20 20:50:55Z pjd $");
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/kernel.h>
33#include <sys/linker.h>
34#include <sys/module.h>
35#include <sys/lock.h>
36#include <sys/mutex.h>

--- 11 unchanged lines hidden (view full) ---

48
49#include <geom/geom.h>
50#include <geom/eli/g_eli.h>
51#include <geom/eli/pkcs5v2.h>
52
53/*
54 * Code paths:
55 * BIO_READ:
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/kernel.h>
33#include <sys/linker.h>
34#include <sys/module.h>
35#include <sys/lock.h>
36#include <sys/mutex.h>

--- 11 unchanged lines hidden (view full) ---

48
49#include <geom/geom.h>
50#include <geom/eli/g_eli.h>
51#include <geom/eli/pkcs5v2.h>
52
53/*
54 * Code paths:
55 * BIO_READ:
56 * g_eli_start -> g_io_request -> g_eli_read_done -> g_eli_crypto_run -> g_eli_crypto_read_done -> g_io_deliver
56 * g_eli_start -> g_eli_crypto_read -> g_io_request -> g_eli_read_done -> g_eli_crypto_run -> g_eli_crypto_read_done -> g_io_deliver
57 * BIO_WRITE:
58 * g_eli_start -> g_eli_crypto_run -> g_eli_crypto_write_done -> g_io_request -> g_eli_write_done -> g_io_deliver
59 */
60
61MALLOC_DECLARE(M_ELI);
62
63/*
64 * The function is called after we read and decrypt data.
65 *
57 * BIO_WRITE:
58 * g_eli_start -> g_eli_crypto_run -> g_eli_crypto_write_done -> g_io_request -> g_eli_write_done -> g_io_deliver
59 */
60
61MALLOC_DECLARE(M_ELI);
62
63/*
64 * The function is called after we read and decrypt data.
65 *
66 * g_eli_start -> g_io_request -> g_eli_read_done -> g_eli_crypto_run -> G_ELI_CRYPTO_READ_DONE -> g_io_deliver
66 * g_eli_start -> g_eli_crypto_read -> g_io_request -> g_eli_read_done -> g_eli_crypto_run -> G_ELI_CRYPTO_READ_DONE -> g_io_deliver
67 */
68static int
69g_eli_crypto_read_done(struct cryptop *crp)
70{
67 */
68static int
69g_eli_crypto_read_done(struct cryptop *crp)
70{
71 struct g_eli_softc *sc;
71 struct bio *bp;
72
73 if (crp->crp_etype == EAGAIN) {
74 if (g_eli_crypto_rerun(crp) == 0)
75 return (0);
76 }
77 bp = (struct bio *)crp->crp_opaque;
78 bp->bio_inbed++;

--- 17 unchanged lines hidden (view full) ---

96 if (bp->bio_error != 0) {
97 G_ELI_LOGREQ(0, bp, "Crypto READ request failed (error=%d).",
98 bp->bio_error);
99 bp->bio_completed = 0;
100 }
101 /*
102 * Read is finished, send it up.
103 */
72 struct bio *bp;
73
74 if (crp->crp_etype == EAGAIN) {
75 if (g_eli_crypto_rerun(crp) == 0)
76 return (0);
77 }
78 bp = (struct bio *)crp->crp_opaque;
79 bp->bio_inbed++;

--- 17 unchanged lines hidden (view full) ---

97 if (bp->bio_error != 0) {
98 G_ELI_LOGREQ(0, bp, "Crypto READ request failed (error=%d).",
99 bp->bio_error);
100 bp->bio_completed = 0;
101 }
102 /*
103 * Read is finished, send it up.
104 */
105 sc = bp->bio_to->geom->softc;
104 g_io_deliver(bp, bp->bio_error);
106 g_io_deliver(bp, bp->bio_error);
107 atomic_subtract_int(&sc->sc_inflight, 1);
105 return (0);
106}
107
108/*
109 * The function is called after data encryption.
110 *
111 * g_eli_start -> g_eli_crypto_run -> G_ELI_CRYPTO_WRITE_DONE -> g_io_request -> g_eli_write_done -> g_io_deliver
112 */
113static int
114g_eli_crypto_write_done(struct cryptop *crp)
115{
108 return (0);
109}
110
111/*
112 * The function is called after data encryption.
113 *
114 * g_eli_start -> g_eli_crypto_run -> G_ELI_CRYPTO_WRITE_DONE -> g_io_request -> g_eli_write_done -> g_io_deliver
115 */
116static int
117g_eli_crypto_write_done(struct cryptop *crp)
118{
119 struct g_eli_softc *sc;
116 struct g_geom *gp;
117 struct g_consumer *cp;
118 struct bio *bp, *cbp;
119
120 if (crp->crp_etype == EAGAIN) {
121 if (g_eli_crypto_rerun(crp) == 0)
122 return (0);
123 }

--- 12 unchanged lines hidden (view full) ---

136 * All sectors are already encrypted?
137 */
138 if (bp->bio_inbed < bp->bio_children)
139 return (0);
140 bp->bio_inbed = 0;
141 bp->bio_children = 1;
142 cbp = bp->bio_driver1;
143 bp->bio_driver1 = NULL;
120 struct g_geom *gp;
121 struct g_consumer *cp;
122 struct bio *bp, *cbp;
123
124 if (crp->crp_etype == EAGAIN) {
125 if (g_eli_crypto_rerun(crp) == 0)
126 return (0);
127 }

--- 12 unchanged lines hidden (view full) ---

140 * All sectors are already encrypted?
141 */
142 if (bp->bio_inbed < bp->bio_children)
143 return (0);
144 bp->bio_inbed = 0;
145 bp->bio_children = 1;
146 cbp = bp->bio_driver1;
147 bp->bio_driver1 = NULL;
148 gp = bp->bio_to->geom;
144 if (bp->bio_error != 0) {
145 G_ELI_LOGREQ(0, bp, "Crypto WRITE request failed (error=%d).",
146 bp->bio_error);
147 free(bp->bio_driver2, M_ELI);
148 bp->bio_driver2 = NULL;
149 g_destroy_bio(cbp);
149 if (bp->bio_error != 0) {
150 G_ELI_LOGREQ(0, bp, "Crypto WRITE request failed (error=%d).",
151 bp->bio_error);
152 free(bp->bio_driver2, M_ELI);
153 bp->bio_driver2 = NULL;
154 g_destroy_bio(cbp);
155 sc = gp->softc;
150 g_io_deliver(bp, bp->bio_error);
156 g_io_deliver(bp, bp->bio_error);
157 atomic_subtract_int(&sc->sc_inflight, 1);
151 return (0);
152 }
153 cbp->bio_data = bp->bio_driver2;
154 cbp->bio_done = g_eli_write_done;
158 return (0);
159 }
160 cbp->bio_data = bp->bio_driver2;
161 cbp->bio_done = g_eli_write_done;
155 gp = bp->bio_to->geom;
156 cp = LIST_FIRST(&gp->consumer);
157 cbp->bio_to = cp->provider;
158 G_ELI_LOGREQ(2, cbp, "Sending request.");
159 /*
160 * Send encrypted data to the provider.
161 */
162 g_io_request(cbp, cp);
163 return (0);
164}
165
166/*
162 cp = LIST_FIRST(&gp->consumer);
163 cbp->bio_to = cp->provider;
164 G_ELI_LOGREQ(2, cbp, "Sending request.");
165 /*
166 * Send encrypted data to the provider.
167 */
168 g_io_request(cbp, cp);
169 return (0);
170}
171
172/*
173 * The function is called to read encrypted data.
174 *
175 * g_eli_start -> G_ELI_CRYPTO_READ -> g_io_request -> g_eli_read_done -> g_eli_crypto_run -> g_eli_crypto_read_done -> g_io_deliver
176 */
177void
178g_eli_crypto_read(struct g_eli_softc *sc, struct bio *bp, boolean_t fromworker)
179{
180 struct g_consumer *cp;
181 struct bio *cbp;
182
183 if (!fromworker) {
184 /*
185 * We are not called from the worker thread, so check if
186 * device is suspended.
187 */
188 mtx_lock(&sc->sc_queue_mtx);
189 if (sc->sc_flags & G_ELI_FLAG_SUSPEND) {
190 /*
191 * If device is suspended, we place the request onto
192 * the queue, so it can be handled after resume.
193 */
194 G_ELI_DEBUG(0, "device suspended, move onto queue");
195 bioq_insert_tail(&sc->sc_queue, bp);
196 mtx_unlock(&sc->sc_queue_mtx);
197 wakeup(sc);
198 return;
199 }
200 atomic_add_int(&sc->sc_inflight, 1);
201 mtx_unlock(&sc->sc_queue_mtx);
202 }
203 bp->bio_pflags = 0;
204 bp->bio_driver2 = NULL;
205 cbp = bp->bio_driver1;
206 cbp->bio_done = g_eli_read_done;
207 cp = LIST_FIRST(&sc->sc_geom->consumer);
208 cbp->bio_to = cp->provider;
209 G_ELI_LOGREQ(2, cbp, "Sending request.");
210 /*
211 * Read encrypted data from provider.
212 */
213 g_io_request(cbp, cp);
214}
215
216/*
167 * This is the main function responsible for cryptography (ie. communication
168 * with crypto(9) subsystem).
169 *
170 * BIO_READ:
217 * This is the main function responsible for cryptography (ie. communication
218 * with crypto(9) subsystem).
219 *
220 * BIO_READ:
171 * g_eli_start -> g_io_request -> g_eli_read_done -> G_ELI_CRYPTO_RUN -> g_eli_crypto_read_done -> g_io_deliver
221 * g_eli_start -> g_eli_crypto_read -> g_io_request -> g_eli_read_done -> G_ELI_CRYPTO_RUN -> g_eli_crypto_read_done -> g_io_deliver
172 * BIO_WRITE:
173 * g_eli_start -> G_ELI_CRYPTO_RUN -> g_eli_crypto_write_done -> g_io_request -> g_eli_write_done -> g_io_deliver
174 */
175void
176g_eli_crypto_run(struct g_eli_worker *wr, struct bio *bp)
177{
178 struct g_eli_softc *sc;
179 struct cryptop *crp;

--- 101 unchanged lines hidden ---
222 * BIO_WRITE:
223 * g_eli_start -> G_ELI_CRYPTO_RUN -> g_eli_crypto_write_done -> g_io_request -> g_eli_write_done -> g_io_deliver
224 */
225void
226g_eli_crypto_run(struct g_eli_worker *wr, struct bio *bp)
227{
228 struct g_eli_softc *sc;
229 struct cryptop *crp;

--- 101 unchanged lines hidden ---