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