diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-03-28 20:19:27 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-03-28 20:19:28 -0400 |
commit | 532bfc851a7475fb6a36c1e953aa395798a7cca7 (patch) | |
tree | a7892e5a31330dd59f31959efbe9fda1803784fd /drivers/block/nbd.c | |
parent | 0195c00244dc2e9f522475868fa278c473ba7339 (diff) | |
parent | 8da00edc1069f01c34510fa405dc15d96c090a3f (diff) |
Merge branch 'akpm' (Andrew's patch-bomb)
Merge third batch of patches from Andrew Morton:
- Some MM stragglers
- core SMP library cleanups (on_each_cpu_mask)
- Some IPI optimisations
- kexec
- kdump
- IPMI
- the radix-tree iterator work
- various other misc bits.
"That'll do for -rc1. I still have ~10 patches for 3.4, will send
those along when they've baked a little more."
* emailed from Andrew Morton <akpm@linux-foundation.org>: (35 commits)
backlight: fix typo in tosa_lcd.c
crc32: add help text for the algorithm select option
mm: move hugepage test examples to tools/testing/selftests/vm
mm: move slabinfo.c to tools/vm
mm: move page-types.c from Documentation to tools/vm
selftests/Makefile: make `run_tests' depend on `all'
selftests: launch individual selftests from the main Makefile
radix-tree: use iterators in find_get_pages* functions
radix-tree: rewrite gang lookup using iterator
radix-tree: introduce bit-optimized iterator
fs/proc/namespaces.c: prevent crash when ns_entries[] is empty
nbd: rename the nbd_device variable from lo to nbd
pidns: add reboot_pid_ns() to handle the reboot syscall
sysctl: use bitmap library functions
ipmi: use locks on watchdog timeout set on reboot
ipmi: simplify locking
ipmi: fix message handling during panics
ipmi: use a tasklet for handling received messages
ipmi: increase KCS timeouts
ipmi: decrease the IPMI message transaction time in interrupt mode
...
Diffstat (limited to 'drivers/block/nbd.c')
-rw-r--r-- | drivers/block/nbd.c | 295 |
1 files changed, 148 insertions, 147 deletions
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index c7ba11f9b203..061427a75d37 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c | |||
@@ -38,7 +38,7 @@ | |||
38 | 38 | ||
39 | #include <linux/nbd.h> | 39 | #include <linux/nbd.h> |
40 | 40 | ||
41 | #define LO_MAGIC 0x68797548 | 41 | #define NBD_MAGIC 0x68797548 |
42 | 42 | ||
43 | #ifdef NDEBUG | 43 | #ifdef NDEBUG |
44 | #define dprintk(flags, fmt...) | 44 | #define dprintk(flags, fmt...) |
@@ -115,7 +115,7 @@ static void nbd_end_request(struct request *req) | |||
115 | spin_unlock_irqrestore(q->queue_lock, flags); | 115 | spin_unlock_irqrestore(q->queue_lock, flags); |
116 | } | 116 | } |
117 | 117 | ||
118 | static void sock_shutdown(struct nbd_device *lo, int lock) | 118 | static void sock_shutdown(struct nbd_device *nbd, int lock) |
119 | { | 119 | { |
120 | /* Forcibly shutdown the socket causing all listeners | 120 | /* Forcibly shutdown the socket causing all listeners |
121 | * to error | 121 | * to error |
@@ -124,14 +124,14 @@ static void sock_shutdown(struct nbd_device *lo, int lock) | |||
124 | * there should be a more generic interface rather than | 124 | * there should be a more generic interface rather than |
125 | * calling socket ops directly here */ | 125 | * calling socket ops directly here */ |
126 | if (lock) | 126 | if (lock) |
127 | mutex_lock(&lo->tx_lock); | 127 | mutex_lock(&nbd->tx_lock); |
128 | if (lo->sock) { | 128 | if (nbd->sock) { |
129 | dev_warn(disk_to_dev(lo->disk), "shutting down socket\n"); | 129 | dev_warn(disk_to_dev(nbd->disk), "shutting down socket\n"); |
130 | kernel_sock_shutdown(lo->sock, SHUT_RDWR); | 130 | kernel_sock_shutdown(nbd->sock, SHUT_RDWR); |
131 | lo->sock = NULL; | 131 | nbd->sock = NULL; |
132 | } | 132 | } |
133 | if (lock) | 133 | if (lock) |
134 | mutex_unlock(&lo->tx_lock); | 134 | mutex_unlock(&nbd->tx_lock); |
135 | } | 135 | } |
136 | 136 | ||
137 | static void nbd_xmit_timeout(unsigned long arg) | 137 | static void nbd_xmit_timeout(unsigned long arg) |
@@ -146,17 +146,17 @@ static void nbd_xmit_timeout(unsigned long arg) | |||
146 | /* | 146 | /* |
147 | * Send or receive packet. | 147 | * Send or receive packet. |
148 | */ | 148 | */ |
149 | static int sock_xmit(struct nbd_device *lo, int send, void *buf, int size, | 149 | static int sock_xmit(struct nbd_device *nbd, int send, void *buf, int size, |
150 | int msg_flags) | 150 | int msg_flags) |
151 | { | 151 | { |
152 | struct socket *sock = lo->sock; | 152 | struct socket *sock = nbd->sock; |
153 | int result; | 153 | int result; |
154 | struct msghdr msg; | 154 | struct msghdr msg; |
155 | struct kvec iov; | 155 | struct kvec iov; |
156 | sigset_t blocked, oldset; | 156 | sigset_t blocked, oldset; |
157 | 157 | ||
158 | if (unlikely(!sock)) { | 158 | if (unlikely(!sock)) { |
159 | dev_err(disk_to_dev(lo->disk), | 159 | dev_err(disk_to_dev(nbd->disk), |
160 | "Attempted %s on closed socket in sock_xmit\n", | 160 | "Attempted %s on closed socket in sock_xmit\n", |
161 | (send ? "send" : "recv")); | 161 | (send ? "send" : "recv")); |
162 | return -EINVAL; | 162 | return -EINVAL; |
@@ -180,15 +180,15 @@ static int sock_xmit(struct nbd_device *lo, int send, void *buf, int size, | |||
180 | if (send) { | 180 | if (send) { |
181 | struct timer_list ti; | 181 | struct timer_list ti; |
182 | 182 | ||
183 | if (lo->xmit_timeout) { | 183 | if (nbd->xmit_timeout) { |
184 | init_timer(&ti); | 184 | init_timer(&ti); |
185 | ti.function = nbd_xmit_timeout; | 185 | ti.function = nbd_xmit_timeout; |
186 | ti.data = (unsigned long)current; | 186 | ti.data = (unsigned long)current; |
187 | ti.expires = jiffies + lo->xmit_timeout; | 187 | ti.expires = jiffies + nbd->xmit_timeout; |
188 | add_timer(&ti); | 188 | add_timer(&ti); |
189 | } | 189 | } |
190 | result = kernel_sendmsg(sock, &msg, &iov, 1, size); | 190 | result = kernel_sendmsg(sock, &msg, &iov, 1, size); |
191 | if (lo->xmit_timeout) | 191 | if (nbd->xmit_timeout) |
192 | del_timer_sync(&ti); | 192 | del_timer_sync(&ti); |
193 | } else | 193 | } else |
194 | result = kernel_recvmsg(sock, &msg, &iov, 1, size, | 194 | result = kernel_recvmsg(sock, &msg, &iov, 1, size, |
@@ -200,7 +200,7 @@ static int sock_xmit(struct nbd_device *lo, int send, void *buf, int size, | |||
200 | task_pid_nr(current), current->comm, | 200 | task_pid_nr(current), current->comm, |
201 | dequeue_signal_lock(current, ¤t->blocked, &info)); | 201 | dequeue_signal_lock(current, ¤t->blocked, &info)); |
202 | result = -EINTR; | 202 | result = -EINTR; |
203 | sock_shutdown(lo, !send); | 203 | sock_shutdown(nbd, !send); |
204 | break; | 204 | break; |
205 | } | 205 | } |
206 | 206 | ||
@@ -218,18 +218,19 @@ static int sock_xmit(struct nbd_device *lo, int send, void *buf, int size, | |||
218 | return result; | 218 | return result; |
219 | } | 219 | } |
220 | 220 | ||
221 | static inline int sock_send_bvec(struct nbd_device *lo, struct bio_vec *bvec, | 221 | static inline int sock_send_bvec(struct nbd_device *nbd, struct bio_vec *bvec, |
222 | int flags) | 222 | int flags) |
223 | { | 223 | { |
224 | int result; | 224 | int result; |
225 | void *kaddr = kmap(bvec->bv_page); | 225 | void *kaddr = kmap(bvec->bv_page); |
226 | result = sock_xmit(lo, 1, kaddr + bvec->bv_offset, bvec->bv_len, flags); | 226 | result = sock_xmit(nbd, 1, kaddr + bvec->bv_offset, |
227 | bvec->bv_len, flags); | ||
227 | kunmap(bvec->bv_page); | 228 | kunmap(bvec->bv_page); |
228 | return result; | 229 | return result; |
229 | } | 230 | } |
230 | 231 | ||
231 | /* always call with the tx_lock held */ | 232 | /* always call with the tx_lock held */ |
232 | static int nbd_send_req(struct nbd_device *lo, struct request *req) | 233 | static int nbd_send_req(struct nbd_device *nbd, struct request *req) |
233 | { | 234 | { |
234 | int result, flags; | 235 | int result, flags; |
235 | struct nbd_request request; | 236 | struct nbd_request request; |
@@ -242,14 +243,14 @@ static int nbd_send_req(struct nbd_device *lo, struct request *req) | |||
242 | memcpy(request.handle, &req, sizeof(req)); | 243 | memcpy(request.handle, &req, sizeof(req)); |
243 | 244 | ||
244 | dprintk(DBG_TX, "%s: request %p: sending control (%s@%llu,%uB)\n", | 245 | dprintk(DBG_TX, "%s: request %p: sending control (%s@%llu,%uB)\n", |
245 | lo->disk->disk_name, req, | 246 | nbd->disk->disk_name, req, |
246 | nbdcmd_to_ascii(nbd_cmd(req)), | 247 | nbdcmd_to_ascii(nbd_cmd(req)), |
247 | (unsigned long long)blk_rq_pos(req) << 9, | 248 | (unsigned long long)blk_rq_pos(req) << 9, |
248 | blk_rq_bytes(req)); | 249 | blk_rq_bytes(req)); |
249 | result = sock_xmit(lo, 1, &request, sizeof(request), | 250 | result = sock_xmit(nbd, 1, &request, sizeof(request), |
250 | (nbd_cmd(req) == NBD_CMD_WRITE) ? MSG_MORE : 0); | 251 | (nbd_cmd(req) == NBD_CMD_WRITE) ? MSG_MORE : 0); |
251 | if (result <= 0) { | 252 | if (result <= 0) { |
252 | dev_err(disk_to_dev(lo->disk), | 253 | dev_err(disk_to_dev(nbd->disk), |
253 | "Send control failed (result %d)\n", result); | 254 | "Send control failed (result %d)\n", result); |
254 | goto error_out; | 255 | goto error_out; |
255 | } | 256 | } |
@@ -266,10 +267,10 @@ static int nbd_send_req(struct nbd_device *lo, struct request *req) | |||
266 | if (!rq_iter_last(req, iter)) | 267 | if (!rq_iter_last(req, iter)) |
267 | flags = MSG_MORE; | 268 | flags = MSG_MORE; |
268 | dprintk(DBG_TX, "%s: request %p: sending %d bytes data\n", | 269 | dprintk(DBG_TX, "%s: request %p: sending %d bytes data\n", |
269 | lo->disk->disk_name, req, bvec->bv_len); | 270 | nbd->disk->disk_name, req, bvec->bv_len); |
270 | result = sock_send_bvec(lo, bvec, flags); | 271 | result = sock_send_bvec(nbd, bvec, flags); |
271 | if (result <= 0) { | 272 | if (result <= 0) { |
272 | dev_err(disk_to_dev(lo->disk), | 273 | dev_err(disk_to_dev(nbd->disk), |
273 | "Send data failed (result %d)\n", | 274 | "Send data failed (result %d)\n", |
274 | result); | 275 | result); |
275 | goto error_out; | 276 | goto error_out; |
@@ -282,25 +283,25 @@ error_out: | |||
282 | return -EIO; | 283 | return -EIO; |
283 | } | 284 | } |
284 | 285 | ||
285 | static struct request *nbd_find_request(struct nbd_device *lo, | 286 | static struct request *nbd_find_request(struct nbd_device *nbd, |
286 | struct request *xreq) | 287 | struct request *xreq) |
287 | { | 288 | { |
288 | struct request *req, *tmp; | 289 | struct request *req, *tmp; |
289 | int err; | 290 | int err; |
290 | 291 | ||
291 | err = wait_event_interruptible(lo->active_wq, lo->active_req != xreq); | 292 | err = wait_event_interruptible(nbd->active_wq, nbd->active_req != xreq); |
292 | if (unlikely(err)) | 293 | if (unlikely(err)) |
293 | goto out; | 294 | goto out; |
294 | 295 | ||
295 | spin_lock(&lo->queue_lock); | 296 | spin_lock(&nbd->queue_lock); |
296 | list_for_each_entry_safe(req, tmp, &lo->queue_head, queuelist) { | 297 | list_for_each_entry_safe(req, tmp, &nbd->queue_head, queuelist) { |
297 | if (req != xreq) | 298 | if (req != xreq) |
298 | continue; | 299 | continue; |
299 | list_del_init(&req->queuelist); | 300 | list_del_init(&req->queuelist); |
300 | spin_unlock(&lo->queue_lock); | 301 | spin_unlock(&nbd->queue_lock); |
301 | return req; | 302 | return req; |
302 | } | 303 | } |
303 | spin_unlock(&lo->queue_lock); | 304 | spin_unlock(&nbd->queue_lock); |
304 | 305 | ||
305 | err = -ENOENT; | 306 | err = -ENOENT; |
306 | 307 | ||
@@ -308,78 +309,78 @@ out: | |||
308 | return ERR_PTR(err); | 309 | return ERR_PTR(err); |
309 | } | 310 | } |
310 | 311 | ||
311 | static inline int sock_recv_bvec(struct nbd_device *lo, struct bio_vec *bvec) | 312 | static inline int sock_recv_bvec(struct nbd_device *nbd, struct bio_vec *bvec) |
312 | { | 313 | { |
313 | int result; | 314 | int result; |
314 | void *kaddr = kmap(bvec->bv_page); | 315 | void *kaddr = kmap(bvec->bv_page); |
315 | result = sock_xmit(lo, 0, kaddr + bvec->bv_offset, bvec->bv_len, | 316 | result = sock_xmit(nbd, 0, kaddr + bvec->bv_offset, bvec->bv_len, |
316 | MSG_WAITALL); | 317 | MSG_WAITALL); |
317 | kunmap(bvec->bv_page); | 318 | kunmap(bvec->bv_page); |
318 | return result; | 319 | return result; |
319 | } | 320 | } |
320 | 321 | ||
321 | /* NULL returned = something went wrong, inform userspace */ | 322 | /* NULL returned = something went wrong, inform userspace */ |
322 | static struct request *nbd_read_stat(struct nbd_device *lo) | 323 | static struct request *nbd_read_stat(struct nbd_device *nbd) |
323 | { | 324 | { |
324 | int result; | 325 | int result; |
325 | struct nbd_reply reply; | 326 | struct nbd_reply reply; |
326 | struct request *req; | 327 | struct request *req; |
327 | 328 | ||
328 | reply.magic = 0; | 329 | reply.magic = 0; |
329 | result = sock_xmit(lo, 0, &reply, sizeof(reply), MSG_WAITALL); | 330 | result = sock_xmit(nbd, 0, &reply, sizeof(reply), MSG_WAITALL); |
330 | if (result <= 0) { | 331 | if (result <= 0) { |
331 | dev_err(disk_to_dev(lo->disk), | 332 | dev_err(disk_to_dev(nbd->disk), |
332 | "Receive control failed (result %d)\n", result); | 333 | "Receive control failed (result %d)\n", result); |
333 | goto harderror; | 334 | goto harderror; |
334 | } | 335 | } |
335 | 336 | ||
336 | if (ntohl(reply.magic) != NBD_REPLY_MAGIC) { | 337 | if (ntohl(reply.magic) != NBD_REPLY_MAGIC) { |
337 | dev_err(disk_to_dev(lo->disk), "Wrong magic (0x%lx)\n", | 338 | dev_err(disk_to_dev(nbd->disk), "Wrong magic (0x%lx)\n", |
338 | (unsigned long)ntohl(reply.magic)); | 339 | (unsigned long)ntohl(reply.magic)); |
339 | result = -EPROTO; | 340 | result = -EPROTO; |
340 | goto harderror; | 341 | goto harderror; |
341 | } | 342 | } |
342 | 343 | ||
343 | req = nbd_find_request(lo, *(struct request **)reply.handle); | 344 | req = nbd_find_request(nbd, *(struct request **)reply.handle); |
344 | if (IS_ERR(req)) { | 345 | if (IS_ERR(req)) { |
345 | result = PTR_ERR(req); | 346 | result = PTR_ERR(req); |
346 | if (result != -ENOENT) | 347 | if (result != -ENOENT) |
347 | goto harderror; | 348 | goto harderror; |
348 | 349 | ||
349 | dev_err(disk_to_dev(lo->disk), "Unexpected reply (%p)\n", | 350 | dev_err(disk_to_dev(nbd->disk), "Unexpected reply (%p)\n", |
350 | reply.handle); | 351 | reply.handle); |
351 | result = -EBADR; | 352 | result = -EBADR; |
352 | goto harderror; | 353 | goto harderror; |
353 | } | 354 | } |
354 | 355 | ||
355 | if (ntohl(reply.error)) { | 356 | if (ntohl(reply.error)) { |
356 | dev_err(disk_to_dev(lo->disk), "Other side returned error (%d)\n", | 357 | dev_err(disk_to_dev(nbd->disk), "Other side returned error (%d)\n", |
357 | ntohl(reply.error)); | 358 | ntohl(reply.error)); |
358 | req->errors++; | 359 | req->errors++; |
359 | return req; | 360 | return req; |
360 | } | 361 | } |
361 | 362 | ||
362 | dprintk(DBG_RX, "%s: request %p: got reply\n", | 363 | dprintk(DBG_RX, "%s: request %p: got reply\n", |
363 | lo->disk->disk_name, req); | 364 | nbd->disk->disk_name, req); |
364 | if (nbd_cmd(req) == NBD_CMD_READ) { | 365 | if (nbd_cmd(req) == NBD_CMD_READ) { |
365 | struct req_iterator iter; | 366 | struct req_iterator iter; |
366 | struct bio_vec *bvec; | 367 | struct bio_vec *bvec; |
367 | 368 | ||
368 | rq_for_each_segment(bvec, req, iter) { | 369 | rq_for_each_segment(bvec, req, iter) { |
369 | result = sock_recv_bvec(lo, bvec); | 370 | result = sock_recv_bvec(nbd, bvec); |
370 | if (result <= 0) { | 371 | if (result <= 0) { |
371 | dev_err(disk_to_dev(lo->disk), "Receive data failed (result %d)\n", | 372 | dev_err(disk_to_dev(nbd->disk), "Receive data failed (result %d)\n", |
372 | result); | 373 | result); |
373 | req->errors++; | 374 | req->errors++; |
374 | return req; | 375 | return req; |
375 | } | 376 | } |
376 | dprintk(DBG_RX, "%s: request %p: got %d bytes data\n", | 377 | dprintk(DBG_RX, "%s: request %p: got %d bytes data\n", |
377 | lo->disk->disk_name, req, bvec->bv_len); | 378 | nbd->disk->disk_name, req, bvec->bv_len); |
378 | } | 379 | } |
379 | } | 380 | } |
380 | return req; | 381 | return req; |
381 | harderror: | 382 | harderror: |
382 | lo->harderror = result; | 383 | nbd->harderror = result; |
383 | return NULL; | 384 | return NULL; |
384 | } | 385 | } |
385 | 386 | ||
@@ -397,48 +398,48 @@ static struct device_attribute pid_attr = { | |||
397 | .show = pid_show, | 398 | .show = pid_show, |
398 | }; | 399 | }; |
399 | 400 | ||
400 | static int nbd_do_it(struct nbd_device *lo) | 401 | static int nbd_do_it(struct nbd_device *nbd) |
401 | { | 402 | { |
402 | struct request *req; | 403 | struct request *req; |
403 | int ret; | 404 | int ret; |
404 | 405 | ||
405 | BUG_ON(lo->magic != LO_MAGIC); | 406 | BUG_ON(nbd->magic != NBD_MAGIC); |
406 | 407 | ||
407 | lo->pid = task_pid_nr(current); | 408 | nbd->pid = task_pid_nr(current); |
408 | ret = device_create_file(disk_to_dev(lo->disk), &pid_attr); | 409 | ret = device_create_file(disk_to_dev(nbd->disk), &pid_attr); |
409 | if (ret) { | 410 | if (ret) { |
410 | dev_err(disk_to_dev(lo->disk), "device_create_file failed!\n"); | 411 | dev_err(disk_to_dev(nbd->disk), "device_create_file failed!\n"); |
411 | lo->pid = 0; | 412 | nbd->pid = 0; |
412 | return ret; | 413 | return ret; |
413 | } | 414 | } |
414 | 415 | ||
415 | while ((req = nbd_read_stat(lo)) != NULL) | 416 | while ((req = nbd_read_stat(nbd)) != NULL) |
416 | nbd_end_request(req); | 417 | nbd_end_request(req); |
417 | 418 | ||
418 | device_remove_file(disk_to_dev(lo->disk), &pid_attr); | 419 | device_remove_file(disk_to_dev(nbd->disk), &pid_attr); |
419 | lo->pid = 0; | 420 | nbd->pid = 0; |
420 | return 0; | 421 | return 0; |
421 | } | 422 | } |
422 | 423 | ||
423 | static void nbd_clear_que(struct nbd_device *lo) | 424 | static void nbd_clear_que(struct nbd_device *nbd) |
424 | { | 425 | { |
425 | struct request *req; | 426 | struct request *req; |
426 | 427 | ||
427 | BUG_ON(lo->magic != LO_MAGIC); | 428 | BUG_ON(nbd->magic != NBD_MAGIC); |
428 | 429 | ||
429 | /* | 430 | /* |
430 | * Because we have set lo->sock to NULL under the tx_lock, all | 431 | * Because we have set nbd->sock to NULL under the tx_lock, all |
431 | * modifications to the list must have completed by now. For | 432 | * modifications to the list must have completed by now. For |
432 | * the same reason, the active_req must be NULL. | 433 | * the same reason, the active_req must be NULL. |
433 | * | 434 | * |
434 | * As a consequence, we don't need to take the spin lock while | 435 | * As a consequence, we don't need to take the spin lock while |
435 | * purging the list here. | 436 | * purging the list here. |
436 | */ | 437 | */ |
437 | BUG_ON(lo->sock); | 438 | BUG_ON(nbd->sock); |
438 | BUG_ON(lo->active_req); | 439 | BUG_ON(nbd->active_req); |
439 | 440 | ||
440 | while (!list_empty(&lo->queue_head)) { | 441 | while (!list_empty(&nbd->queue_head)) { |
441 | req = list_entry(lo->queue_head.next, struct request, | 442 | req = list_entry(nbd->queue_head.next, struct request, |
442 | queuelist); | 443 | queuelist); |
443 | list_del_init(&req->queuelist); | 444 | list_del_init(&req->queuelist); |
444 | req->errors++; | 445 | req->errors++; |
@@ -447,7 +448,7 @@ static void nbd_clear_que(struct nbd_device *lo) | |||
447 | } | 448 | } |
448 | 449 | ||
449 | 450 | ||
450 | static void nbd_handle_req(struct nbd_device *lo, struct request *req) | 451 | static void nbd_handle_req(struct nbd_device *nbd, struct request *req) |
451 | { | 452 | { |
452 | if (req->cmd_type != REQ_TYPE_FS) | 453 | if (req->cmd_type != REQ_TYPE_FS) |
453 | goto error_out; | 454 | goto error_out; |
@@ -455,8 +456,8 @@ static void nbd_handle_req(struct nbd_device *lo, struct request *req) | |||
455 | nbd_cmd(req) = NBD_CMD_READ; | 456 | nbd_cmd(req) = NBD_CMD_READ; |
456 | if (rq_data_dir(req) == WRITE) { | 457 | if (rq_data_dir(req) == WRITE) { |
457 | nbd_cmd(req) = NBD_CMD_WRITE; | 458 | nbd_cmd(req) = NBD_CMD_WRITE; |
458 | if (lo->flags & NBD_READ_ONLY) { | 459 | if (nbd->flags & NBD_READ_ONLY) { |
459 | dev_err(disk_to_dev(lo->disk), | 460 | dev_err(disk_to_dev(nbd->disk), |
460 | "Write on read-only\n"); | 461 | "Write on read-only\n"); |
461 | goto error_out; | 462 | goto error_out; |
462 | } | 463 | } |
@@ -464,29 +465,29 @@ static void nbd_handle_req(struct nbd_device *lo, struct request *req) | |||
464 | 465 | ||
465 | req->errors = 0; | 466 | req->errors = 0; |
466 | 467 | ||
467 | mutex_lock(&lo->tx_lock); | 468 | mutex_lock(&nbd->tx_lock); |
468 | if (unlikely(!lo->sock)) { | 469 | if (unlikely(!nbd->sock)) { |
469 | mutex_unlock(&lo->tx_lock); | 470 | mutex_unlock(&nbd->tx_lock); |
470 | dev_err(disk_to_dev(lo->disk), | 471 | dev_err(disk_to_dev(nbd->disk), |
471 | "Attempted send on closed socket\n"); | 472 | "Attempted send on closed socket\n"); |
472 | goto error_out; | 473 | goto error_out; |
473 | } | 474 | } |
474 | 475 | ||
475 | lo->active_req = req; | 476 | nbd->active_req = req; |
476 | 477 | ||
477 | if (nbd_send_req(lo, req) != 0) { | 478 | if (nbd_send_req(nbd, req) != 0) { |
478 | dev_err(disk_to_dev(lo->disk), "Request send failed\n"); | 479 | dev_err(disk_to_dev(nbd->disk), "Request send failed\n"); |
479 | req->errors++; | 480 | req->errors++; |
480 | nbd_end_request(req); | 481 | nbd_end_request(req); |
481 | } else { | 482 | } else { |
482 | spin_lock(&lo->queue_lock); | 483 | spin_lock(&nbd->queue_lock); |
483 | list_add(&req->queuelist, &lo->queue_head); | 484 | list_add(&req->queuelist, &nbd->queue_head); |
484 | spin_unlock(&lo->queue_lock); | 485 | spin_unlock(&nbd->queue_lock); |
485 | } | 486 | } |
486 | 487 | ||
487 | lo->active_req = NULL; | 488 | nbd->active_req = NULL; |
488 | mutex_unlock(&lo->tx_lock); | 489 | mutex_unlock(&nbd->tx_lock); |
489 | wake_up_all(&lo->active_wq); | 490 | wake_up_all(&nbd->active_wq); |
490 | 491 | ||
491 | return; | 492 | return; |
492 | 493 | ||
@@ -497,28 +498,28 @@ error_out: | |||
497 | 498 | ||
498 | static int nbd_thread(void *data) | 499 | static int nbd_thread(void *data) |
499 | { | 500 | { |
500 | struct nbd_device *lo = data; | 501 | struct nbd_device *nbd = data; |
501 | struct request *req; | 502 | struct request *req; |
502 | 503 | ||
503 | set_user_nice(current, -20); | 504 | set_user_nice(current, -20); |
504 | while (!kthread_should_stop() || !list_empty(&lo->waiting_queue)) { | 505 | while (!kthread_should_stop() || !list_empty(&nbd->waiting_queue)) { |
505 | /* wait for something to do */ | 506 | /* wait for something to do */ |
506 | wait_event_interruptible(lo->waiting_wq, | 507 | wait_event_interruptible(nbd->waiting_wq, |
507 | kthread_should_stop() || | 508 | kthread_should_stop() || |
508 | !list_empty(&lo->waiting_queue)); | 509 | !list_empty(&nbd->waiting_queue)); |
509 | 510 | ||
510 | /* extract request */ | 511 | /* extract request */ |
511 | if (list_empty(&lo->waiting_queue)) | 512 | if (list_empty(&nbd->waiting_queue)) |
512 | continue; | 513 | continue; |
513 | 514 | ||
514 | spin_lock_irq(&lo->queue_lock); | 515 | spin_lock_irq(&nbd->queue_lock); |
515 | req = list_entry(lo->waiting_queue.next, struct request, | 516 | req = list_entry(nbd->waiting_queue.next, struct request, |
516 | queuelist); | 517 | queuelist); |
517 | list_del_init(&req->queuelist); | 518 | list_del_init(&req->queuelist); |
518 | spin_unlock_irq(&lo->queue_lock); | 519 | spin_unlock_irq(&nbd->queue_lock); |
519 | 520 | ||
520 | /* handle request */ | 521 | /* handle request */ |
521 | nbd_handle_req(lo, req); | 522 | nbd_handle_req(nbd, req); |
522 | } | 523 | } |
523 | return 0; | 524 | return 0; |
524 | } | 525 | } |
@@ -526,7 +527,7 @@ static int nbd_thread(void *data) | |||
526 | /* | 527 | /* |
527 | * We always wait for result of write, for now. It would be nice to make it optional | 528 | * We always wait for result of write, for now. It would be nice to make it optional |
528 | * in future | 529 | * in future |
529 | * if ((rq_data_dir(req) == WRITE) && (lo->flags & NBD_WRITE_NOCHK)) | 530 | * if ((rq_data_dir(req) == WRITE) && (nbd->flags & NBD_WRITE_NOCHK)) |
530 | * { printk( "Warning: Ignoring result!\n"); nbd_end_request( req ); } | 531 | * { printk( "Warning: Ignoring result!\n"); nbd_end_request( req ); } |
531 | */ | 532 | */ |
532 | 533 | ||
@@ -535,19 +536,19 @@ static void do_nbd_request(struct request_queue *q) | |||
535 | struct request *req; | 536 | struct request *req; |
536 | 537 | ||
537 | while ((req = blk_fetch_request(q)) != NULL) { | 538 | while ((req = blk_fetch_request(q)) != NULL) { |
538 | struct nbd_device *lo; | 539 | struct nbd_device *nbd; |
539 | 540 | ||
540 | spin_unlock_irq(q->queue_lock); | 541 | spin_unlock_irq(q->queue_lock); |
541 | 542 | ||
542 | dprintk(DBG_BLKDEV, "%s: request %p: dequeued (flags=%x)\n", | 543 | dprintk(DBG_BLKDEV, "%s: request %p: dequeued (flags=%x)\n", |
543 | req->rq_disk->disk_name, req, req->cmd_type); | 544 | req->rq_disk->disk_name, req, req->cmd_type); |
544 | 545 | ||
545 | lo = req->rq_disk->private_data; | 546 | nbd = req->rq_disk->private_data; |
546 | 547 | ||
547 | BUG_ON(lo->magic != LO_MAGIC); | 548 | BUG_ON(nbd->magic != NBD_MAGIC); |
548 | 549 | ||
549 | if (unlikely(!lo->sock)) { | 550 | if (unlikely(!nbd->sock)) { |
550 | dev_err(disk_to_dev(lo->disk), | 551 | dev_err(disk_to_dev(nbd->disk), |
551 | "Attempted send on closed socket\n"); | 552 | "Attempted send on closed socket\n"); |
552 | req->errors++; | 553 | req->errors++; |
553 | nbd_end_request(req); | 554 | nbd_end_request(req); |
@@ -555,11 +556,11 @@ static void do_nbd_request(struct request_queue *q) | |||
555 | continue; | 556 | continue; |
556 | } | 557 | } |
557 | 558 | ||
558 | spin_lock_irq(&lo->queue_lock); | 559 | spin_lock_irq(&nbd->queue_lock); |
559 | list_add_tail(&req->queuelist, &lo->waiting_queue); | 560 | list_add_tail(&req->queuelist, &nbd->waiting_queue); |
560 | spin_unlock_irq(&lo->queue_lock); | 561 | spin_unlock_irq(&nbd->queue_lock); |
561 | 562 | ||
562 | wake_up(&lo->waiting_wq); | 563 | wake_up(&nbd->waiting_wq); |
563 | 564 | ||
564 | spin_lock_irq(q->queue_lock); | 565 | spin_lock_irq(q->queue_lock); |
565 | } | 566 | } |
@@ -567,32 +568,32 @@ static void do_nbd_request(struct request_queue *q) | |||
567 | 568 | ||
568 | /* Must be called with tx_lock held */ | 569 | /* Must be called with tx_lock held */ |
569 | 570 | ||
570 | static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo, | 571 | static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd, |
571 | unsigned int cmd, unsigned long arg) | 572 | unsigned int cmd, unsigned long arg) |
572 | { | 573 | { |
573 | switch (cmd) { | 574 | switch (cmd) { |
574 | case NBD_DISCONNECT: { | 575 | case NBD_DISCONNECT: { |
575 | struct request sreq; | 576 | struct request sreq; |
576 | 577 | ||
577 | dev_info(disk_to_dev(lo->disk), "NBD_DISCONNECT\n"); | 578 | dev_info(disk_to_dev(nbd->disk), "NBD_DISCONNECT\n"); |
578 | 579 | ||
579 | blk_rq_init(NULL, &sreq); | 580 | blk_rq_init(NULL, &sreq); |
580 | sreq.cmd_type = REQ_TYPE_SPECIAL; | 581 | sreq.cmd_type = REQ_TYPE_SPECIAL; |
581 | nbd_cmd(&sreq) = NBD_CMD_DISC; | 582 | nbd_cmd(&sreq) = NBD_CMD_DISC; |
582 | if (!lo->sock) | 583 | if (!nbd->sock) |
583 | return -EINVAL; | 584 | return -EINVAL; |
584 | nbd_send_req(lo, &sreq); | 585 | nbd_send_req(nbd, &sreq); |
585 | return 0; | 586 | return 0; |
586 | } | 587 | } |
587 | 588 | ||
588 | case NBD_CLEAR_SOCK: { | 589 | case NBD_CLEAR_SOCK: { |
589 | struct file *file; | 590 | struct file *file; |
590 | 591 | ||
591 | lo->sock = NULL; | 592 | nbd->sock = NULL; |
592 | file = lo->file; | 593 | file = nbd->file; |
593 | lo->file = NULL; | 594 | nbd->file = NULL; |
594 | nbd_clear_que(lo); | 595 | nbd_clear_que(nbd); |
595 | BUG_ON(!list_empty(&lo->queue_head)); | 596 | BUG_ON(!list_empty(&nbd->queue_head)); |
596 | if (file) | 597 | if (file) |
597 | fput(file); | 598 | fput(file); |
598 | return 0; | 599 | return 0; |
@@ -600,14 +601,14 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo, | |||
600 | 601 | ||
601 | case NBD_SET_SOCK: { | 602 | case NBD_SET_SOCK: { |
602 | struct file *file; | 603 | struct file *file; |
603 | if (lo->file) | 604 | if (nbd->file) |
604 | return -EBUSY; | 605 | return -EBUSY; |
605 | file = fget(arg); | 606 | file = fget(arg); |
606 | if (file) { | 607 | if (file) { |
607 | struct inode *inode = file->f_path.dentry->d_inode; | 608 | struct inode *inode = file->f_path.dentry->d_inode; |
608 | if (S_ISSOCK(inode->i_mode)) { | 609 | if (S_ISSOCK(inode->i_mode)) { |
609 | lo->file = file; | 610 | nbd->file = file; |
610 | lo->sock = SOCKET_I(inode); | 611 | nbd->sock = SOCKET_I(inode); |
611 | if (max_part > 0) | 612 | if (max_part > 0) |
612 | bdev->bd_invalidated = 1; | 613 | bdev->bd_invalidated = 1; |
613 | return 0; | 614 | return 0; |
@@ -619,29 +620,29 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo, | |||
619 | } | 620 | } |
620 | 621 | ||
621 | case NBD_SET_BLKSIZE: | 622 | case NBD_SET_BLKSIZE: |
622 | lo->blksize = arg; | 623 | nbd->blksize = arg; |
623 | lo->bytesize &= ~(lo->blksize-1); | 624 | nbd->bytesize &= ~(nbd->blksize-1); |
624 | bdev->bd_inode->i_size = lo->bytesize; | 625 | bdev->bd_inode->i_size = nbd->bytesize; |
625 | set_blocksize(bdev, lo->blksize); | 626 | set_blocksize(bdev, nbd->blksize); |
626 | set_capacity(lo->disk, lo->bytesize >> 9); | 627 | set_capacity(nbd->disk, nbd->bytesize >> 9); |
627 | return 0; | 628 | return 0; |
628 | 629 | ||
629 | case NBD_SET_SIZE: | 630 | case NBD_SET_SIZE: |
630 | lo->bytesize = arg & ~(lo->blksize-1); | 631 | nbd->bytesize = arg & ~(nbd->blksize-1); |
631 | bdev->bd_inode->i_size = lo->bytesize; | 632 | bdev->bd_inode->i_size = nbd->bytesize; |
632 | set_blocksize(bdev, lo->blksize); | 633 | set_blocksize(bdev, nbd->blksize); |
633 | set_capacity(lo->disk, lo->bytesize >> 9); | 634 | set_capacity(nbd->disk, nbd->bytesize >> 9); |
634 | return 0; | 635 | return 0; |
635 | 636 | ||
636 | case NBD_SET_TIMEOUT: | 637 | case NBD_SET_TIMEOUT: |
637 | lo->xmit_timeout = arg * HZ; | 638 | nbd->xmit_timeout = arg * HZ; |
638 | return 0; | 639 | return 0; |
639 | 640 | ||
640 | case NBD_SET_SIZE_BLOCKS: | 641 | case NBD_SET_SIZE_BLOCKS: |
641 | lo->bytesize = ((u64) arg) * lo->blksize; | 642 | nbd->bytesize = ((u64) arg) * nbd->blksize; |
642 | bdev->bd_inode->i_size = lo->bytesize; | 643 | bdev->bd_inode->i_size = nbd->bytesize; |
643 | set_blocksize(bdev, lo->blksize); | 644 | set_blocksize(bdev, nbd->blksize); |
644 | set_capacity(lo->disk, lo->bytesize >> 9); | 645 | set_capacity(nbd->disk, nbd->bytesize >> 9); |
645 | return 0; | 646 | return 0; |
646 | 647 | ||
647 | case NBD_DO_IT: { | 648 | case NBD_DO_IT: { |
@@ -649,38 +650,38 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo, | |||
649 | struct file *file; | 650 | struct file *file; |
650 | int error; | 651 | int error; |
651 | 652 | ||
652 | if (lo->pid) | 653 | if (nbd->pid) |
653 | return -EBUSY; | 654 | return -EBUSY; |
654 | if (!lo->file) | 655 | if (!nbd->file) |
655 | return -EINVAL; | 656 | return -EINVAL; |
656 | 657 | ||
657 | mutex_unlock(&lo->tx_lock); | 658 | mutex_unlock(&nbd->tx_lock); |
658 | 659 | ||
659 | thread = kthread_create(nbd_thread, lo, lo->disk->disk_name); | 660 | thread = kthread_create(nbd_thread, nbd, nbd->disk->disk_name); |
660 | if (IS_ERR(thread)) { | 661 | if (IS_ERR(thread)) { |
661 | mutex_lock(&lo->tx_lock); | 662 | mutex_lock(&nbd->tx_lock); |
662 | return PTR_ERR(thread); | 663 | return PTR_ERR(thread); |
663 | } | 664 | } |
664 | wake_up_process(thread); | 665 | wake_up_process(thread); |
665 | error = nbd_do_it(lo); | 666 | error = nbd_do_it(nbd); |
666 | kthread_stop(thread); | 667 | kthread_stop(thread); |
667 | 668 | ||
668 | mutex_lock(&lo->tx_lock); | 669 | mutex_lock(&nbd->tx_lock); |
669 | if (error) | 670 | if (error) |
670 | return error; | 671 | return error; |
671 | sock_shutdown(lo, 0); | 672 | sock_shutdown(nbd, 0); |
672 | file = lo->file; | 673 | file = nbd->file; |
673 | lo->file = NULL; | 674 | nbd->file = NULL; |
674 | nbd_clear_que(lo); | 675 | nbd_clear_que(nbd); |
675 | dev_warn(disk_to_dev(lo->disk), "queue cleared\n"); | 676 | dev_warn(disk_to_dev(nbd->disk), "queue cleared\n"); |
676 | if (file) | 677 | if (file) |
677 | fput(file); | 678 | fput(file); |
678 | lo->bytesize = 0; | 679 | nbd->bytesize = 0; |
679 | bdev->bd_inode->i_size = 0; | 680 | bdev->bd_inode->i_size = 0; |
680 | set_capacity(lo->disk, 0); | 681 | set_capacity(nbd->disk, 0); |
681 | if (max_part > 0) | 682 | if (max_part > 0) |
682 | ioctl_by_bdev(bdev, BLKRRPART, 0); | 683 | ioctl_by_bdev(bdev, BLKRRPART, 0); |
683 | return lo->harderror; | 684 | return nbd->harderror; |
684 | } | 685 | } |
685 | 686 | ||
686 | case NBD_CLEAR_QUE: | 687 | case NBD_CLEAR_QUE: |
@@ -688,14 +689,14 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo, | |||
688 | * This is for compatibility only. The queue is always cleared | 689 | * This is for compatibility only. The queue is always cleared |
689 | * by NBD_DO_IT or NBD_CLEAR_SOCK. | 690 | * by NBD_DO_IT or NBD_CLEAR_SOCK. |
690 | */ | 691 | */ |
691 | BUG_ON(!lo->sock && !list_empty(&lo->queue_head)); | 692 | BUG_ON(!nbd->sock && !list_empty(&nbd->queue_head)); |
692 | return 0; | 693 | return 0; |
693 | 694 | ||
694 | case NBD_PRINT_DEBUG: | 695 | case NBD_PRINT_DEBUG: |
695 | dev_info(disk_to_dev(lo->disk), | 696 | dev_info(disk_to_dev(nbd->disk), |
696 | "next = %p, prev = %p, head = %p\n", | 697 | "next = %p, prev = %p, head = %p\n", |
697 | lo->queue_head.next, lo->queue_head.prev, | 698 | nbd->queue_head.next, nbd->queue_head.prev, |
698 | &lo->queue_head); | 699 | &nbd->queue_head); |
699 | return 0; | 700 | return 0; |
700 | } | 701 | } |
701 | return -ENOTTY; | 702 | return -ENOTTY; |
@@ -704,21 +705,21 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo, | |||
704 | static int nbd_ioctl(struct block_device *bdev, fmode_t mode, | 705 | static int nbd_ioctl(struct block_device *bdev, fmode_t mode, |
705 | unsigned int cmd, unsigned long arg) | 706 | unsigned int cmd, unsigned long arg) |
706 | { | 707 | { |
707 | struct nbd_device *lo = bdev->bd_disk->private_data; | 708 | struct nbd_device *nbd = bdev->bd_disk->private_data; |
708 | int error; | 709 | int error; |
709 | 710 | ||
710 | if (!capable(CAP_SYS_ADMIN)) | 711 | if (!capable(CAP_SYS_ADMIN)) |
711 | return -EPERM; | 712 | return -EPERM; |
712 | 713 | ||
713 | BUG_ON(lo->magic != LO_MAGIC); | 714 | BUG_ON(nbd->magic != NBD_MAGIC); |
714 | 715 | ||
715 | /* Anyone capable of this syscall can do *real bad* things */ | 716 | /* Anyone capable of this syscall can do *real bad* things */ |
716 | dprintk(DBG_IOCTL, "%s: nbd_ioctl cmd=%s(0x%x) arg=%lu\n", | 717 | dprintk(DBG_IOCTL, "%s: nbd_ioctl cmd=%s(0x%x) arg=%lu\n", |
717 | lo->disk->disk_name, ioctl_cmd_to_ascii(cmd), cmd, arg); | 718 | nbd->disk->disk_name, ioctl_cmd_to_ascii(cmd), cmd, arg); |
718 | 719 | ||
719 | mutex_lock(&lo->tx_lock); | 720 | mutex_lock(&nbd->tx_lock); |
720 | error = __nbd_ioctl(bdev, lo, cmd, arg); | 721 | error = __nbd_ioctl(bdev, nbd, cmd, arg); |
721 | mutex_unlock(&lo->tx_lock); | 722 | mutex_unlock(&nbd->tx_lock); |
722 | 723 | ||
723 | return error; | 724 | return error; |
724 | } | 725 | } |
@@ -804,7 +805,7 @@ static int __init nbd_init(void) | |||
804 | for (i = 0; i < nbds_max; i++) { | 805 | for (i = 0; i < nbds_max; i++) { |
805 | struct gendisk *disk = nbd_dev[i].disk; | 806 | struct gendisk *disk = nbd_dev[i].disk; |
806 | nbd_dev[i].file = NULL; | 807 | nbd_dev[i].file = NULL; |
807 | nbd_dev[i].magic = LO_MAGIC; | 808 | nbd_dev[i].magic = NBD_MAGIC; |
808 | nbd_dev[i].flags = 0; | 809 | nbd_dev[i].flags = 0; |
809 | INIT_LIST_HEAD(&nbd_dev[i].waiting_queue); | 810 | INIT_LIST_HEAD(&nbd_dev[i].waiting_queue); |
810 | spin_lock_init(&nbd_dev[i].queue_lock); | 811 | spin_lock_init(&nbd_dev[i].queue_lock); |