~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise-security

« back to all changes in this revision

Viewing changes to drivers/block/nbd.c

  • Committer: Package Import Robot
  • Author(s): Paolo Pisati, Paolo Pisati
  • Date: 2011-12-06 15:56:07 UTC
  • Revision ID: package-import@ubuntu.com-20111206155607-pcf44kv5fmhk564f
Tags: 3.2.0-1401.1
[ Paolo Pisati ]

* Rebased on top of Ubuntu-3.2.0-3.8
* Tilt-tracking @ ef2487af4bb15bdd0689631774b5a5e3a59f74e2
* Delete debian.ti-omap4/control, it shoudln't be tracked
* Fix architecture spelling (s/armel/armhf/)
* [Config] Update configs following 3.2 import
* [Config] Fix compilation: disable CODA and ARCH_OMAP3
* [Config] Fix compilation: disable Ethernet Faraday
* Update series to precise

Show diffs side-by-side

added added

removed removed

Lines of Context:
127
127
        if (lock)
128
128
                mutex_lock(&lo->tx_lock);
129
129
        if (lo->sock) {
130
 
                printk(KERN_WARNING "%s: shutting down socket\n",
131
 
                        lo->disk->disk_name);
 
130
                dev_warn(disk_to_dev(lo->disk), "shutting down socket\n");
132
131
                kernel_sock_shutdown(lo->sock, SHUT_RDWR);
133
132
                lo->sock = NULL;
134
133
        }
158
157
        sigset_t blocked, oldset;
159
158
 
160
159
        if (unlikely(!sock)) {
161
 
                printk(KERN_ERR "%s: Attempted %s on closed socket in sock_xmit\n",
162
 
                       lo->disk->disk_name, (send ? "send" : "recv"));
 
160
                dev_err(disk_to_dev(lo->disk),
 
161
                        "Attempted %s on closed socket in sock_xmit\n",
 
162
                        (send ? "send" : "recv"));
163
163
                return -EINVAL;
164
164
        }
165
165
 
250
250
        result = sock_xmit(lo, 1, &request, sizeof(request),
251
251
                        (nbd_cmd(req) == NBD_CMD_WRITE) ? MSG_MORE : 0);
252
252
        if (result <= 0) {
253
 
                printk(KERN_ERR "%s: Send control failed (result %d)\n",
254
 
                                lo->disk->disk_name, result);
 
253
                dev_err(disk_to_dev(lo->disk),
 
254
                        "Send control failed (result %d)\n", result);
255
255
                goto error_out;
256
256
        }
257
257
 
270
270
                                        lo->disk->disk_name, req, bvec->bv_len);
271
271
                        result = sock_send_bvec(lo, bvec, flags);
272
272
                        if (result <= 0) {
273
 
                                printk(KERN_ERR "%s: Send data failed (result %d)\n",
274
 
                                                lo->disk->disk_name, result);
 
273
                                dev_err(disk_to_dev(lo->disk),
 
274
                                        "Send data failed (result %d)\n",
 
275
                                        result);
275
276
                                goto error_out;
276
277
                        }
277
278
                }
328
329
        reply.magic = 0;
329
330
        result = sock_xmit(lo, 0, &reply, sizeof(reply), MSG_WAITALL);
330
331
        if (result <= 0) {
331
 
                printk(KERN_ERR "%s: Receive control failed (result %d)\n",
332
 
                                lo->disk->disk_name, result);
 
332
                dev_err(disk_to_dev(lo->disk),
 
333
                        "Receive control failed (result %d)\n", result);
333
334
                goto harderror;
334
335
        }
335
336
 
336
337
        if (ntohl(reply.magic) != NBD_REPLY_MAGIC) {
337
 
                printk(KERN_ERR "%s: Wrong magic (0x%lx)\n",
338
 
                                lo->disk->disk_name,
 
338
                dev_err(disk_to_dev(lo->disk), "Wrong magic (0x%lx)\n",
339
339
                                (unsigned long)ntohl(reply.magic));
340
340
                result = -EPROTO;
341
341
                goto harderror;
347
347
                if (result != -ENOENT)
348
348
                        goto harderror;
349
349
 
350
 
                printk(KERN_ERR "%s: Unexpected reply (%p)\n",
351
 
                                lo->disk->disk_name, reply.handle);
 
350
                dev_err(disk_to_dev(lo->disk), "Unexpected reply (%p)\n",
 
351
                        reply.handle);
352
352
                result = -EBADR;
353
353
                goto harderror;
354
354
        }
355
355
 
356
356
        if (ntohl(reply.error)) {
357
 
                printk(KERN_ERR "%s: Other side returned error (%d)\n",
358
 
                                lo->disk->disk_name, ntohl(reply.error));
 
357
                dev_err(disk_to_dev(lo->disk), "Other side returned error (%d)\n",
 
358
                        ntohl(reply.error));
359
359
                req->errors++;
360
360
                return req;
361
361
        }
369
369
                rq_for_each_segment(bvec, req, iter) {
370
370
                        result = sock_recv_bvec(lo, bvec);
371
371
                        if (result <= 0) {
372
 
                                printk(KERN_ERR "%s: Receive data failed (result %d)\n",
373
 
                                                lo->disk->disk_name, result);
 
372
                                dev_err(disk_to_dev(lo->disk), "Receive data failed (result %d)\n",
 
373
                                        result);
374
374
                                req->errors++;
375
375
                                return req;
376
376
                        }
405
405
 
406
406
        BUG_ON(lo->magic != LO_MAGIC);
407
407
 
408
 
        lo->pid = current->pid;
409
 
        ret = sysfs_create_file(&disk_to_dev(lo->disk)->kobj, &pid_attr.attr);
 
408
        lo->pid = task_pid_nr(current);
 
409
        ret = device_create_file(disk_to_dev(lo->disk), &pid_attr);
410
410
        if (ret) {
411
 
                printk(KERN_ERR "nbd: sysfs_create_file failed!");
 
411
                dev_err(disk_to_dev(lo->disk), "device_create_file failed!\n");
412
412
                lo->pid = 0;
413
413
                return ret;
414
414
        }
416
416
        while ((req = nbd_read_stat(lo)) != NULL)
417
417
                nbd_end_request(req);
418
418
 
419
 
        sysfs_remove_file(&disk_to_dev(lo->disk)->kobj, &pid_attr.attr);
 
419
        device_remove_file(disk_to_dev(lo->disk), &pid_attr);
420
420
        lo->pid = 0;
421
421
        return 0;
422
422
}
457
457
        if (rq_data_dir(req) == WRITE) {
458
458
                nbd_cmd(req) = NBD_CMD_WRITE;
459
459
                if (lo->flags & NBD_READ_ONLY) {
460
 
                        printk(KERN_ERR "%s: Write on read-only\n",
461
 
                                        lo->disk->disk_name);
 
460
                        dev_err(disk_to_dev(lo->disk),
 
461
                                "Write on read-only\n");
462
462
                        goto error_out;
463
463
                }
464
464
        }
468
468
        mutex_lock(&lo->tx_lock);
469
469
        if (unlikely(!lo->sock)) {
470
470
                mutex_unlock(&lo->tx_lock);
471
 
                printk(KERN_ERR "%s: Attempted send on closed socket\n",
472
 
                       lo->disk->disk_name);
 
471
                dev_err(disk_to_dev(lo->disk),
 
472
                        "Attempted send on closed socket\n");
473
473
                goto error_out;
474
474
        }
475
475
 
476
476
        lo->active_req = req;
477
477
 
478
478
        if (nbd_send_req(lo, req) != 0) {
479
 
                printk(KERN_ERR "%s: Request send failed\n",
480
 
                                lo->disk->disk_name);
 
479
                dev_err(disk_to_dev(lo->disk), "Request send failed\n");
481
480
                req->errors++;
482
481
                nbd_end_request(req);
483
482
        } else {
549
548
                BUG_ON(lo->magic != LO_MAGIC);
550
549
 
551
550
                if (unlikely(!lo->sock)) {
552
 
                        printk(KERN_ERR "%s: Attempted send on closed socket\n",
553
 
                                lo->disk->disk_name);
 
551
                        dev_err(disk_to_dev(lo->disk),
 
552
                                "Attempted send on closed socket\n");
554
553
                        req->errors++;
555
554
                        nbd_end_request(req);
556
555
                        spin_lock_irq(q->queue_lock);
576
575
        case NBD_DISCONNECT: {
577
576
                struct request sreq;
578
577
 
579
 
                printk(KERN_INFO "%s: NBD_DISCONNECT\n", lo->disk->disk_name);
 
578
                dev_info(disk_to_dev(lo->disk), "NBD_DISCONNECT\n");
580
579
 
581
580
                blk_rq_init(NULL, &sreq);
582
581
                sreq.cmd_type = REQ_TYPE_SPECIAL;
674
673
                file = lo->file;
675
674
                lo->file = NULL;
676
675
                nbd_clear_que(lo);
677
 
                printk(KERN_WARNING "%s: queue cleared\n", lo->disk->disk_name);
 
676
                dev_warn(disk_to_dev(lo->disk), "queue cleared\n");
678
677
                if (file)
679
678
                        fput(file);
680
679
                lo->bytesize = 0;
694
693
                return 0;
695
694
 
696
695
        case NBD_PRINT_DEBUG:
697
 
                printk(KERN_INFO "%s: next = %p, prev = %p, head = %p\n",
698
 
                        bdev->bd_disk->disk_name,
 
696
                dev_info(disk_to_dev(lo->disk),
 
697
                        "next = %p, prev = %p, head = %p\n",
699
698
                        lo->queue_head.next, lo->queue_head.prev,
700
699
                        &lo->queue_head);
701
700
                return 0;
745
744
        BUILD_BUG_ON(sizeof(struct nbd_request) != 28);
746
745
 
747
746
        if (max_part < 0) {
748
 
                printk(KERN_CRIT "nbd: max_part must be >= 0\n");
 
747
                printk(KERN_ERR "nbd: max_part must be >= 0\n");
749
748
                return -EINVAL;
750
749
        }
751
750