示例#1
0
static int __init mbd_init(void)
{
	int err = -ENOMEM;
	int i;

	for (i = 0; i < MAX_MBD; i++) {
		struct gendisk *disk = alloc_disk(1);
		if (!disk)
			goto out;
		mbd_dev[i].disk = disk;
		/*
		 * The new linux 2.5 block layer implementation requires
		 * every gendisk to have its very own request_queue struct.
		 * These structs are big so we dynamically allocate them.
		 */
		disk->queue = blk_init_queue(do_mbd_request, &mbd_lock);
		if (!disk->queue) {
			put_disk(disk);
			goto out;
		}
	}

	if (register_blkdev(MAJOR_NR, "mbd")) {
		err = -EIO;
		goto out;
	}
#ifdef MODULE
	printk("mambo bogus disk: registered device at major %d\n", MAJOR_NR);
#else
	printk("mambo bogus disk: compiled in with kernel\n");
#endif

	devfs_mk_dir("mambobd");
	for (i = 0; i < MAX_MBD; i++) {	/* load defaults */
		struct gendisk *disk = mbd_dev[i].disk;
		mbd_dev[i].initialized = 0;
		mbd_dev[i].refcnt = 0;
		mbd_dev[i].flags = 0;
		disk->major = MAJOR_NR;
		disk->first_minor = i;
		disk->fops = &mbd_fops;
		disk->private_data = &mbd_dev[i];
		sprintf(disk->disk_name, "mambobd%d", i);
		sprintf(disk->devfs_name, "mambobd%d", i);
		set_capacity(disk, 0x7ffffc00ULL << 1);	/* 2 TB */
		add_disk(disk);
	}

	return 0;
      out:
	while (i--) {
		if (mbd_dev[i].disk->queue)
			blk_cleanup_queue(mbd_dev[i].disk->queue);
		put_disk(mbd_dev[i].disk);
	}
	return -EIO;
}
示例#2
0
void
prep_prelaunch_bootrootlv (const char *filename, prep_data *data)
{
  if (vg_lv_parse (data->params[0], NULL, NULL) == -1)
    prep_error (data, filename, _("incorrect format for LV name, use '/dev/VG/LV'"));

  if (alloc_disk (filename, data->params[3], 0, 1) == -1)
    prep_error (data, filename, _("failed to allocate disk"));
}
示例#3
0
/**
 * add_last_partition : add card last partition as a full device, refer to
 * board-****.c  inand_partition_info[] last partition
 * @card: inand_card_lp
 * @size: set last partition capacity
 */
int add_last_partition(struct memory_card* card, uint64_t offset ,uint64_t size)
{
      struct card_blk_data *card_data;
      int ret;

      card_data = kmalloc(sizeof(struct card_blk_data), GFP_KERNEL);
      if (!card_data) {
            ret = -ENOMEM;
            return ret;
      }

      memset(card_data, 0, sizeof(struct card_blk_data));

      if(card->state & CARD_STATE_READONLY)
            card_data->read_only = 1;

      card_data->block_bits = 9;

      card_data->disk = alloc_disk(1 << CARD_SHIFT);
      if (card_data->disk == NULL) {
            ret = -ENOMEM;
            kfree(card_data);
            return ret;
      }

      spin_lock_init(&card_data->lock);
      card_data->usage = 1;

      ret = card_init_queue(&card_data->queue, card, &card_data->lock);
      if (ret) {
            put_disk(card_data->disk);
            return ret;
      }

      card->part_offset=offset;
      card_data->queue.prep_fn = card_blk_prep_rq;
      card_data->queue.issue_fn = card_blk_issue_rq;
      card_data->queue.data = card_data;

      card_data->disk->major = INAND_LAST_PART_MAJOR;
      card_data->disk->minors = 1 << CARD_SHIFT;
      card_data->disk->first_minor = 0;
      card_data->disk->fops = &card_ops;
      card_data->disk->private_data = card_data;
      card_data->disk->queue = card_data->queue.queue;
      card_data->disk->driverfs_dev = &card->dev;

      sprintf(card_data->disk->disk_name, "cardblk%s", card->name);

      blk_queue_logical_block_size(card_data->queue.queue, 1 << card_data->block_bits);

      set_capacity(card_data->disk, size);
      card_set_drvdata(card, card_data);
      add_disk(card_data->disk);
      return 0;
}
/* alloc_disk and add_disk can sleep */
void
aoeblk_gdalloc(void *vp)
{
	struct aoedev *d = vp;
	struct gendisk *gd;
	ulong flags;

	gd = alloc_disk(AOE_PARTITIONS);
	if (gd == NULL) {
		printk(KERN_ERR
			"aoe: cannot allocate disk structure for %ld.%d\n",
			d->aoemajor, d->aoeminor);
		goto err;
	}

	d->bufpool = mempool_create_slab_pool(MIN_BUFS, buf_pool_cache);
	if (d->bufpool == NULL) {
		printk(KERN_ERR "aoe: cannot allocate bufpool for %ld.%d\n",
			d->aoemajor, d->aoeminor);
		goto err_disk;
	}

	d->blkq = blk_alloc_queue(GFP_KERNEL);
	if (!d->blkq)
		goto err_mempool;
	blk_queue_make_request(d->blkq, aoeblk_make_request);
	d->blkq->backing_dev_info.name = "aoe";
	spin_lock_irqsave(&d->lock, flags);
	gd->major = AOE_MAJOR;
	gd->first_minor = d->sysminor * AOE_PARTITIONS;
	gd->fops = &aoe_bdops;
	gd->private_data = d;
	set_capacity(gd, d->ssize);
	snprintf(gd->disk_name, sizeof gd->disk_name, "etherd/e%ld.%d",
		d->aoemajor, d->aoeminor);

	gd->queue = d->blkq;
	d->gd = gd;
	d->flags &= ~DEVFL_GDALLOC;
	d->flags |= DEVFL_UP;

	spin_unlock_irqrestore(&d->lock, flags);

	add_disk(gd);
	aoedisk_add_sysfs(d);
	return;

err_mempool:
	mempool_destroy(d->bufpool);
err_disk:
	put_disk(gd);
err:
	spin_lock_irqsave(&d->lock, flags);
	d->flags &= ~DEVFL_GDALLOC;
	spin_unlock_irqrestore(&d->lock, flags);
}
示例#5
0
/* alloc_disk and add_disk can sleep */
void
aoeblk_gdalloc(void *vp)
{
	struct aoedev *d = vp;
	struct gendisk *gd;
	ulong flags;

	gd = alloc_disk(AOE_PARTITIONS);
	if (gd == NULL) {
		printk(KERN_ERR "aoe: aoeblk_gdalloc: cannot allocate disk "
			"structure for %ld.%ld\n", d->aoemajor, d->aoeminor);
		spin_lock_irqsave(&d->lock, flags);
		d->flags &= ~DEVFL_WORKON;
		spin_unlock_irqrestore(&d->lock, flags);
		return;
	}

	d->bufpool = mempool_create(MIN_BUFS,
				    mempool_alloc_slab, mempool_free_slab,
				    buf_pool_cache);
	if (d->bufpool == NULL) {
		printk(KERN_ERR "aoe: aoeblk_gdalloc: cannot allocate bufpool "
			"for %ld.%ld\n", d->aoemajor, d->aoeminor);
		put_disk(gd);
		spin_lock_irqsave(&d->lock, flags);
		d->flags &= ~DEVFL_WORKON;
		spin_unlock_irqrestore(&d->lock, flags);
		return;
	}

	spin_lock_irqsave(&d->lock, flags);
	blk_queue_make_request(&d->blkq, aoeblk_make_request);
	gd->major = AOE_MAJOR;
	gd->first_minor = d->sysminor * AOE_PARTITIONS;
	gd->fops = &aoe_bdops;
	gd->private_data = d;
	gd->capacity = d->ssize;
	snprintf(gd->disk_name, sizeof gd->disk_name, "etherd/e%ld.%ld",
		d->aoemajor, d->aoeminor);

	gd->queue = &d->blkq;
	d->gd = gd;
	d->flags &= ~DEVFL_WORKON;
	d->flags |= DEVFL_UP;

	spin_unlock_irqrestore(&d->lock, flags);

	add_disk(gd);
	aoedisk_add_sysfs(d);
	
	printk(KERN_INFO "aoe: %012llx e%lu.%lu v%04x has %llu "
		"sectors\n", (unsigned long long)mac_addr(d->addr),
		d->aoemajor, d->aoeminor,
		d->fw_ver, (long long)d->ssize);
}
示例#6
0
static void tc20(void) {
	struct gendisk *gd_ptr;

	gd_ptr = alloc_disk(1);
	if (!gd_ptr) {
		return;
	}
	printk(KERN_DEBUG "gd_ptr after alloc=%p\n", gd_ptr);

	del_gendisk(gd_ptr);
}
static void setup_blk_device(struct ramdisk_dev* dev)
{
    mutex_init(&dev->mutex);
    init_waitqueue_head(&dev->waitqueue);

    /*
     * Get some memory.
     */
    memset (dev, 0, sizeof (struct ramdisk_dev));
    dev->size = NSECTORS*HARDSECT_SIZE;
    dev->data = vmalloc(dev->size);
    if (dev->data == NULL) {
        printk (KERN_NOTICE "vmalloc failure.\n");
        return;
    }
    spin_lock_init(&dev->lock);
    
    /*
     * The timer which "invalidates" the device.
     */
    init_timer(&dev->timer);
    dev->timer.data = (unsigned long) dev;
    dev->timer.function = ramdisk_invalidate;
    
    dev->queue = blk_init_queue(ramdisk_request, &dev->lock);
    if (dev->queue == NULL)
        goto out_vfree;

    blk_queue_logical_block_size(dev->queue, HARDSECT_SIZE);
    dev->queue->queuedata = dev;
    /*
     * And the gendisk structure.
     */
    dev->gd = alloc_disk(BLK_MINORS);
    if (! dev->gd) {
        printk (KERN_NOTICE "alloc_disk failure\n");
        goto out_vfree;
    }
    dev->gd->major = blk_major;
    dev->gd->first_minor = BLK_MINORS;
    dev->gd->fops = &ramdisk_ops;
    dev->gd->queue = dev->queue;
    dev->gd->private_data = dev;
    snprintf (dev->gd->disk_name, 32, "ramdisk%c", 'a');
    set_capacity(dev->gd, NSECTORS*(HARDSECT_SIZE/KERNEL_SECTOR_SIZE));
//    set_capacity(dev->gd, 0);
    add_disk(dev->gd);
    return;

  out_vfree:
    if (dev->data)
        vfree(dev->data);
}
示例#8
0
文件: zvol.c 项目: nordaux/zfs
/*
 * Allocate memory for a new zvol_state_t and setup the required
 * request queue and generic disk structures for the block device.
 */
static zvol_state_t *
zvol_alloc(dev_t dev, const char *name)
{
    zvol_state_t *zv;

    zv = kmem_zalloc(sizeof (zvol_state_t), KM_SLEEP);
    if (zv == NULL)
        goto out;

    zv->zv_queue = blk_init_queue(zvol_request, &zv->zv_lock);
    if (zv->zv_queue == NULL)
        goto out_kmem;

#ifdef HAVE_BLK_QUEUE_FLUSH
    blk_queue_flush(zv->zv_queue, VDEV_REQ_FLUSH | VDEV_REQ_FUA);
#else
    blk_queue_ordered(zv->zv_queue, QUEUE_ORDERED_DRAIN, NULL);
#endif /* HAVE_BLK_QUEUE_FLUSH */

    zv->zv_disk = alloc_disk(ZVOL_MINORS);
    if (zv->zv_disk == NULL)
        goto out_queue;

    zv->zv_queue->queuedata = zv;
    zv->zv_dev = dev;
    zv->zv_open_count = 0;
    strlcpy(zv->zv_name, name, MAXNAMELEN);

    mutex_init(&zv->zv_znode.z_range_lock, NULL, MUTEX_DEFAULT, NULL);
    avl_create(&zv->zv_znode.z_range_avl, zfs_range_compare,
               sizeof (rl_t), offsetof(rl_t, r_node));
    zv->zv_znode.z_is_zvol = TRUE;

    spin_lock_init(&zv->zv_lock);
    list_link_init(&zv->zv_next);

    zv->zv_disk->major = zvol_major;
    zv->zv_disk->first_minor = (dev & MINORMASK);
    zv->zv_disk->fops = &zvol_ops;
    zv->zv_disk->private_data = zv;
    zv->zv_disk->queue = zv->zv_queue;
    snprintf(zv->zv_disk->disk_name, DISK_NAME_LEN, "%s%d",
             ZVOL_DEV_NAME, (dev & MINORMASK));

    return zv;

out_queue:
    blk_cleanup_queue(zv->zv_queue);
out_kmem:
    kmem_free(zv, sizeof (zvol_state_t));
out:
    return NULL;
}
示例#9
0
static int __init looper_init(void) {
  
  if (filename == NULL) {
    printk(KERN_WARNING "looper: no filename defined");
    return -1;
  }

  /*
   * Set up our internal device.
   */
  Device.size = nsectors * logical_block_size;
  spin_lock_init(&Device.lock);
  Device.data = vmalloc(Device.size);
  if (Device.data == NULL)
    return -ENOMEM;
  /*
   * Get a request queue.
   */
  Queue = blk_init_queue(looper_request, &Device.lock);
  if (Queue == NULL)
    goto out;
  blk_queue_logical_block_size(Queue, logical_block_size);
  /*
   * Get registered.
   */
  major_num = register_blkdev(major_num, "looper");
  if (major_num <= 0) {
    printk(KERN_WARNING "looper: unable to get major number\n");
    goto out;
  }
  /*
   * And the gendisk structure.
   */
  Device.gd = alloc_disk(16);
  if (!Device.gd)
    goto out_unregister;
  Device.gd->major = major_num;
  Device.gd->first_minor = 0;
  Device.gd->fops = &looper_ops;
  Device.gd->private_data = &Device;
  strcpy(Device.gd->disk_name, "looper0");
  set_capacity(Device.gd, nsectors);
  Device.gd->queue = Queue;
  add_disk(Device.gd);
  
  return 0;
  
 out_unregister:
  unregister_blkdev(major_num, "looper");
 out:
  vfree(Device.data);
  return -ENOMEM;
}
示例#10
0
/*
 * Allocate and register gendisk structure for device.
 */
int dasd_gendisk_alloc(struct dasd_block *block)
{
	struct gendisk *gdp;
	struct dasd_device *base;
	int len;

	/* Make sure the minor for this device exists. */
	base = block->base;
	if (base->devindex >= DASD_PER_MAJOR)
		return -EBUSY;

	gdp = alloc_disk(1 << DASD_PARTN_BITS);
	if (!gdp)
		return -ENOMEM;

	/* Initialize gendisk structure. */
	gdp->major = DASD_MAJOR;
	gdp->first_minor = base->devindex << DASD_PARTN_BITS;
	gdp->fops = &dasd_device_operations;
	gdp->driverfs_dev = &base->cdev->dev;

	/*
	 * Set device name.
	 *   dasda - dasdz : 26 devices
	 *   dasdaa - dasdzz : 676 devices, added up = 702
	 *   dasdaaa - dasdzzz : 17576 devices, added up = 18278
	 *   dasdaaaa - dasdzzzz : 456976 devices, added up = 475252
	 */
	len = sprintf(gdp->disk_name, "dasd");
	if (base->devindex > 25) {
		if (base->devindex > 701) {
			if (base->devindex > 18277)
			        len += sprintf(gdp->disk_name + len, "%c",
					       'a'+(((base->devindex-18278)
						     /17576)%26));
			len += sprintf(gdp->disk_name + len, "%c",
				       'a'+(((base->devindex-702)/676)%26));
		}
		len += sprintf(gdp->disk_name + len, "%c",
			       'a'+(((base->devindex-26)/26)%26));
	}
	len += sprintf(gdp->disk_name + len, "%c", 'a'+(base->devindex%26));

	if (base->features & DASD_FEATURE_READONLY ||
	    test_bit(DASD_FLAG_DEVICE_RO, &base->flags))
		set_disk_ro(gdp, 1);
	gdp->private_data = block;
	gdp->queue = block->request_queue;
	block->gdp = gdp;
	set_capacity(block->gdp, 0);
	add_disk(block->gdp);
	return 0;
}
示例#11
0
/*
 * Allocate and register gendisk structure for device.
 */
int
dasd_gendisk_alloc(struct dasd_device *device)
{
	struct gendisk *gdp;
	int len;

	/* Make sure the minor for this device exists. */
	if (device->devindex >= DASD_PER_MAJOR)
		return -EBUSY;

	gdp = alloc_disk(1 << DASD_PARTN_BITS);
	if (!gdp)
		return -ENOMEM;

	/* Initialize gendisk structure. */
	gdp->major = DASD_MAJOR;
	gdp->first_minor = device->devindex << DASD_PARTN_BITS;
	gdp->fops = &dasd_device_operations;
	gdp->driverfs_dev = &device->cdev->dev;

	/*
	 * Set device name.
	 *   dasda - dasdz : 26 devices
	 *   dasdaa - dasdzz : 676 devices, added up = 702
	 *   dasdaaa - dasdzzz : 17576 devices, added up = 18278
	 *   dasdaaaa - dasdzzzz : 456976 devices, added up = 475252
	 */
	len = sprintf(gdp->disk_name, "dasd");
	if (device->devindex > 25) {
	        if (device->devindex > 701) {
		        if (device->devindex > 18277)
			        len += sprintf(gdp->disk_name + len, "%c",
					       'a'+(((device->devindex-18278)
						     /17576)%26));
			len += sprintf(gdp->disk_name + len, "%c",
				       'a'+(((device->devindex-702)/676)%26));
		}
		len += sprintf(gdp->disk_name + len, "%c",
			       'a'+(((device->devindex-26)/26)%26));
	}
	len += sprintf(gdp->disk_name + len, "%c", 'a'+(device->devindex%26));

 	sprintf(gdp->devfs_name, "dasd/%s", device->cdev->dev.bus_id);

	if (test_bit(DASD_FLAG_RO, &device->flags))
		set_disk_ro(gdp, 1);
	gdp->private_data = device;
	gdp->queue = device->request_queue;
	device->gdp = gdp;
	set_capacity(device->gdp, 0);
	add_disk(device->gdp);
	return 0;
}
示例#12
0
文件: includeTest.c 项目: 1587/ltp
static int test_init_module(void)
{

	int rc;

	printk("starting module\n");

	ltp_pm_dev = pm_register(PM_UNKNOWN_DEV, 0, ltp_pm_callback);
	rc = register_blkdev(INCLUDEMAJOR, DEVICE_NAME);

	printk("BLK INC - result =%d major %d\n", rc, INCLUDEMAJOR);

	if (rc < 0) {
		printk("Failed to register device.\n");
		return rc;
	}

	gd_ptr = kmalloc(sizeof(struct gendisk *), GFP_KERNEL);
	if (!gd_ptr) {
		printk(KERN_ALERT "ERROR getting memory !!!\n");
		return 0;
	}

	printk("major = %d\n", Major);
	gd_ptr = alloc_disk(1);
	printk(KERN_ALERT "gd_ptr after alloc = %p \n", gd_ptr);
	gd_ptr->major = INCLUDEMAJOR;
	gd_ptr->first_minor = 0;
	gd_ptr->fops = &bdops;
//      gd_ptr->minor_shift= MINOR_SHIFT_BITS;
	gd_ptr->driverfs_dev = NULL;
	gd_ptr->capacity = MAX_NUM_DISKS;
//      gd_ptr->disk_de = NULL;
	gd_ptr->flags = genhd_flags;

	sprintf(gd_ptr->disk_name, DEVICE_NAME);
	add_disk(gd_ptr);

	printk("major = %d\n", Major);

	test_acpi();
	test_vga();
	test_lockd();
	test_sunrpc_auth();
	test_nfsfh();
	test_sunrpc_cache();
	test_sunrpc_svc();
	test_sunrpc_timer();
	printk("finished module\n");

	return 0;
}
static int __init virtualblockdevice_init(void)
{
	int ret;

	printk(KERN_ALERT "VirtualBlockDevice: Entry virtualblockdevice_init !\n");

	ret = register_blkdev( virtualblockdevice_major, VIRTUALBLOCKDEVICE_NAME );
	if( 0 > ret ) {
		printk(KERN_ALERT "VirtualBlockDevice: Failure to register block device: virtualblockdevice ! Major: %d\tErrno: %d !\n", virtualblockdevice_major, ret);
		goto failure_register_blkdev;
	}
	virtualblockdevice_major = ret;
	printk(KERN_ALERT "VirtualBlockDevice: Success to register block device: virtualblockdevice ! Major: %d !\n", virtualblockdevice_major);

	// get request_queue
	virtualblockdevice_queue = blk_init_queue( virtualblockdevice_do_request, NULL );
	if( !virtualblockdevice_queue ) {
		printk(KERN_ALERT "VirtualBlockDevice: Failure to init request_queue !\n");
		ret = -ENOMEM;
		goto failure_init_queue;
	}
	printk(KERN_ALERT "VirtualBlockDevice: Success to init request_queue !\n");

	// get gendisk
	virtualblockdevice_disk = alloc_disk( 1 );
	if( !virtualblockdevice_disk ) {
		printk(KERN_ALERT "VirtualBlockDevice: Failure to allocate gendisk !\n");
		ret = -ENOMEM;
		goto failure_alloc_disk;
	}
	printk(KERN_ALERT "VirtualBlockDevice: Success to allocate gendisk !\n");

	// initialize gendisk
	strcpy( virtualblockdevice_disk->disk_name, VIRTUALBLOCKDEVICE_NAME );
	virtualblockdevice_disk->major = virtualblockdevice_major;
	virtualblockdevice_disk->first_minor = virtualblockdevice_minor;
	virtualblockdevice_disk->fops = &virtualblockdevice_fops;
	virtualblockdevice_disk->queue = virtualblockdevice_queue;
	set_capacity( virtualblockdevice_disk, ( VIRTUALBLOCKDEVICE_DISK_CAPACITY >> 9 ) );

	// add gendisk to kernel
	add_disk( virtualblockdevice_disk );

	return 0;

failure_alloc_disk:
	blk_cleanup_queue( virtualblockdevice_queue );
failure_init_queue:
	unregister_blkdev( virtualblockdevice_major, VIRTUALBLOCKDEVICE_NAME );
failure_register_blkdev:
	return ret;
}
示例#14
0
int
run_sparse (const char *cmd, size_t argc, char *argv[])
{
  if (argc != 2) {
    fprintf (stderr, _("use 'sparse file size' to create a sparse image\n"));
    return -1;
  }

  if (alloc_disk (argv[0], argv[1], 1, 1) == -1)
    return -1;

  return 0;
}
示例#15
0
static int __init chargement (void)
{
	int ret;

	if ((nb_sect_exemple <= 0) || (lg_sect_exemple <= 0))
		return -EINVAL;

	data_exemple = vmalloc(nb_sect_exemple * lg_sect_exemple);
	if (data_exemple == NULL)
		return -ENOMEM;

	ret = register_blkdev(majeur_exemple, nom_exemple);
	if (ret < 0) {
		vfree(data_exemple);
		return ret;
	}

	if (majeur_exemple == 0)
		majeur_exemple = ret;

	spin_lock_init(& spinlock_exemple);

	request_queue_exemple = blk_init_queue(request_exemple,
	                                       & spinlock_exemple);
	if (request_queue_exemple == NULL) {
		unregister_blkdev(majeur_exemple, nom_exemple);
		vfree(data_exemple);
		return -ENOMEM;
	}

	gendisk_exemple = alloc_disk(NB_MINEURS);
	if (gendisk_exemple == NULL) {
		blk_cleanup_queue(request_queue_exemple);
		unregister_blkdev(majeur_exemple, nom_exemple);
		vfree(data_exemple);
		return -ENOMEM;
	}
	gendisk_exemple->major       = majeur_exemple;
	gendisk_exemple->first_minor = 0;
	gendisk_exemple->fops        = & devops_exemple;
	gendisk_exemple->queue       = request_queue_exemple;
	snprintf(gendisk_exemple->disk_name, 32, nom_exemple);

	/* La capacite doit toujours etre indiquee en nombre de secteurs
	 * de 512 octets. Il faut donc faire une conversion. */

	set_capacity(gendisk_exemple, nb_sect_exemple * lg_sect_exemple / 512);
	add_disk(gendisk_exemple);
		
	return 0; 
}
示例#16
0
/*
* Set up our internal device.
*/
static void setup_device(struct sbull_dev *dev, int which)
{
	/*
	* Get some memory.
	*/
	memset (dev, 0, sizeof (struct sbull_dev));
	dev->size = nsectors*hardsect_size;
	dev->data = vmalloc(dev->size);
	if (dev->data == NULL) {
	   printk (KERN_NOTICE "vmalloc failure.\n");
	   return;
	}
	spin_lock_init(&dev->lock);

	/*
	* The timer which "invalidates" the device.
	*/
	init_timer(&dev->timer);
	dev->timer.data = (unsigned long) dev;
	dev->timer.function = sbull_invalidate;


	dev->queue = blk_init_queue(sbull_request, &dev->lock);
	if (dev->queue == NULL)
		goto out_vfree;


	blk_queue_logical_block_size(dev->queue, hardsect_size);
	dev->queue->queuedata = dev;
	/*
	* And the gendisk structure.
	*/
	dev->gd = alloc_disk(SBULL_MINORS);
	if (! dev->gd) {
	   printk (KERN_NOTICE "alloc_disk failure\n");
	   goto out_vfree;
	}
	dev->gd->major = sbull_major;
	dev->gd->first_minor = which*SBULL_MINORS;
	dev->gd->fops = &sbull_ops;
	dev->gd->queue = dev->queue;
	dev->gd->private_data = dev;
	snprintf (dev->gd->disk_name, 32, "sbull%c", which + 'a');
	set_capacity(dev->gd, nsectors*(hardsect_size/KERNEL_SECTOR_SIZE));
	add_disk(dev->gd);
	return;

	out_vfree:
	if (dev->data)
	   vfree(dev->data);
}
示例#17
0
static int __init stheno_module_init( void )
{
    stheno_major = register_blkdev( 0, MODNAME );
    if( stheno_major <= 0 ){
	printk( KERN_WARNING "register_blkdev failed\n" );
        return stheno_major;
    }

    spin_lock_init( &stheno_lock );
    stheno_queue = blk_init_queue(
        stheno_request, //
        &stheno_lock );
    if( ! stheno_queue ){
	printk( KERN_WARNING "blk_init_queue failed\n" );        
        unregister_blkdev( stheno_major, MODNAME );
        return -ENOMEM;
    }
   	blk_queue_logical_block_size( stheno_queue, SECT_SIZE );
    blk_queue_max_sectors( stheno_queue, MAX_SECTORS );
	blk_queue_bounce_limit(stheno_queue, BLK_BOUNCE_ANY);

    stheno_gd = alloc_disk( MINOR_COUNT );
    if( ! stheno_gd ){
	printk( KERN_WARNING "alloc_disk failed\n" );        
        blk_cleanup_queue( stheno_queue );
        unregister_blkdev( stheno_major, MODNAME );
        return -ENOMEM;
    }
    sprintf( stheno_gd->disk_name, "%s", MODNAME ); //
    stheno_gd->queue = stheno_queue; //
    stheno_gd->major = stheno_major;
    stheno_gd->first_minor = 0;
    stheno_gd->fops = &stheno_fops;  //
    set_capacity( stheno_gd, SECT_NUM );

    sema_init(&stheno_sem, 1);
    init_waitqueue_head(&stheno_process_q);

    stheno_thread = kthread_create(stheno_do_request, 0, "sthenod");
    
    wake_up_process(stheno_thread);


    add_disk( stheno_gd );

    printk( KERN_INFO "stheno is loaded\n" );
    printk( KERN_INFO "major = %d\n", stheno_major );

    return 0;
}
示例#18
0
static int __init sbd_init(void) {
	
	crypt_cipher = crypto_alloc_cipher("aes", 0, 0);
	
	/*  Set up our internal device. */
	Device.size = nsectors * logical_block_size;
	spin_lock_init(&Device.lock);
	Device.data = vmalloc(Device.size);
	if (Device.data == NULL) {
		return -ENOMEM;
	}
	
	/* Get a request queue. */
	Queue = blk_init_queue(sbd_request, &Device.lock);
	if (Queue == NULL) {
		goto out;
	}
	blk_queue_logical_block_size(Queue, logical_block_size);
	
	/* Get registered. */
	major_num = register_blkdev(major_num, "sbd");
	if (major_num < 0) {
		printk(KERN_WARNING "sbd: unable to get major number\n");
		goto out;
	}
	
	/* And the gendisk structure. */
	Device.gd = alloc_disk(16);
	if (!Device.gd) {
		goto out_unregister;
	}
	
	Device.gd->major = major_num;
	Device.gd->first_minor = 0;
	Device.gd->fops = &sbd_ops;
	Device.gd->private_data = &Device;
	strcpy(Device.gd->disk_name, "sbd0");
	set_capacity(Device.gd, nsectors);
	Device.gd->queue = Queue;
	add_disk(Device.gd);
	
	return 0;
	
out_unregister:
	unregister_blkdev(major_num, "sbd");
out:
	vfree(Device.data);
	return -ENOMEM;
}
示例#19
0
/*
 * Initializes the block layer interfaces.
 */
static int sd_init_blk_dev(struct sd_host *host)
{
	struct gendisk *disk;
	struct request_queue *queue;
	int channel;
	int retval;

	channel = to_channel(exi_get_exi_channel(host->exi_device));

	/* queue */
	retval = -ENOMEM;
	spin_lock_init(&host->queue_lock);
	queue = blk_init_queue(sd_request_func, &host->queue_lock);
	if (!queue) {
		sd_printk(KERN_ERR, "error initializing queue\n");
		goto err_blk_init_queue;
	}
	blk_queue_dma_alignment(queue, EXI_DMA_ALIGN);
	blk_queue_max_phys_segments(queue, 1);
	blk_queue_max_hw_segments(queue, 1);
	blk_queue_max_sectors(queue, 8);
	queue_flag_set_unlocked(QUEUE_FLAG_NONROT, queue);
	queue->queuedata = host;
	host->queue = queue;

	/* disk */
	disk = alloc_disk(1 << MMC_SHIFT);
	if (!disk) {
		sd_printk(KERN_ERR, "error allocating disk\n");
		goto err_alloc_disk;
	}
	disk->major = SD_MAJOR;
	disk->first_minor = channel << MMC_SHIFT;
	disk->fops = &sd_fops;
	sprintf(disk->disk_name, "%s%c", SD_NAME, 'a' + channel);
	disk->private_data = host;
	disk->queue = host->queue;
	host->disk = disk;

	retval = 0;
	goto out;

err_alloc_disk:
	blk_cleanup_queue(host->queue);
	host->queue = NULL;
err_blk_init_queue:
out:
	return retval;
}
示例#20
0
文件: aoeblk.c 项目: gizm0n/wl500g
/* alloc_disk and add_disk can sleep */
void
aoeblk_gdalloc(void *vp)
{
	struct aoedev *d = vp;
	struct gendisk *gd;
	ulong flags;

	gd = alloc_disk(AOE_PARTITIONS);
	if (gd == NULL) {
		printk(KERN_ERR "aoe: cannot allocate disk structure for %ld.%ld\n",
			d->aoemajor, d->aoeminor);
		spin_lock_irqsave(&d->lock, flags);
		d->flags &= ~DEVFL_GDALLOC;
		spin_unlock_irqrestore(&d->lock, flags);
		return;
	}

	d->bufpool = mempool_create_slab_pool(MIN_BUFS, buf_pool_cache);
	if (d->bufpool == NULL) {
		printk(KERN_ERR "aoe: cannot allocate bufpool for %ld.%ld\n",
			d->aoemajor, d->aoeminor);
		put_disk(gd);
		spin_lock_irqsave(&d->lock, flags);
		d->flags &= ~DEVFL_GDALLOC;
		spin_unlock_irqrestore(&d->lock, flags);
		return;
	}

	spin_lock_irqsave(&d->lock, flags);
	blk_queue_make_request(&d->blkq, aoeblk_make_request);
	gd->major = AOE_MAJOR;
	gd->first_minor = d->sysminor * AOE_PARTITIONS;
	gd->fops = &aoe_bdops;
	gd->private_data = d;
	gd->capacity = d->ssize;
	snprintf(gd->disk_name, sizeof gd->disk_name, "etherd/e%ld.%ld",
		d->aoemajor, d->aoeminor);

	gd->queue = &d->blkq;
	d->gd = gd;
	d->flags &= ~DEVFL_GDALLOC;
	d->flags |= DEVFL_UP;

	spin_unlock_irqrestore(&d->lock, flags);

	add_disk(gd);
	aoedisk_add_sysfs(d);
}
示例#21
0
static int __init simpleblockinit(void)
{
/*
* Set up our internal device.
	*/
    Device.size = nsectors*hardsect_size;
    spin_lock_init(&Device.lock);
    Device.data = vmalloc(Device.size);
    if (Device.data == NULL)
		return -ENOMEM;
		/*
		* Get a request queue.
	*/
    Queue = blk_init_queue(simpleblockrequest, &Device.lock);
    if (Queue == NULL)
		goto out;
    blk_queue_hardsect_size(Queue, hardsect_size);
	/*
	* Get registered.
	*/
    major_num = register_blkdev(major_num, "sbd");
    if (major_num <= 0) {
		printk(KERN_WARNING "sbd: unable to get major number\n");
		goto out;
    }
	/*
	* And the gendisk structure.
	*/
    Device.gd = alloc_disk(16);
    if (! Device.gd)
		goto out_unregister;
    Device.gd->major = major_num;
    Device.gd->first_minor = 0;
    Device.gd->fops = &simpleblockops;
    Device.gd->private_data = &Device;
    strcpy (Device.gd->disk_name, "sbd0");
    set_capacity(Device.gd, nsectors*(hardsect_size/KERNEL_SECTOR_SIZE));
    Device.gd->queue = Queue;
    add_disk(Device.gd);
	
    return 0;
	
out_unregister:
    unregister_blkdev(major_num, "sbd");
out:
    vfree(Device.data);
    return -ENOMEM;
}
示例#22
0
static int __init my_init (void)
{
    disk_size = diskmb * 1024 * 1024;
    spin_lock_init (&lock);

    if (!(my_dev = vmalloc (disk_size)))
        return -ENOMEM;

    if (!(my_request_queue = blk_init_queue (my_request, &lock))) {
        vfree (my_dev);
        return -ENOMEM;
    }

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31)
    blk_queue_hardsect_size (my_request_queue, sector_size);
#else
    blk_queue_logical_block_size (my_request_queue, sector_size);
#endif

    mybdrv_ma_no = register_blkdev (mybdrv_ma_no, MY_DEVICE_NAME);
    if (mybdrv_ma_no < 0) {
        printk (KERN_ERR "Failed registering mybdrv, returned %d\n",
                mybdrv_ma_no);
        vfree (my_dev);
        return mybdrv_ma_no;
    }

    if (!(my_gd = alloc_disk (16))) {
        unregister_blkdev (mybdrv_ma_no, MY_DEVICE_NAME);
        vfree (my_dev);
        return -ENOMEM;
    }

    my_gd->major = mybdrv_ma_no;
    my_gd->first_minor = 0;
    my_gd->fops = &mybdrv_fops;
    strcpy (my_gd->disk_name, MY_DEVICE_NAME);
    my_gd->queue = my_request_queue;
    set_capacity (my_gd, disk_size / sector_size);
    add_disk (my_gd);

    printk (KERN_INFO "device successfully   registered, Major No. = %d\n",
            mybdrv_ma_no);
    printk (KERN_INFO "Capacity of ram disk is: %d MB\n", diskmb);

    return 0;
}
示例#23
0
static int __init stackbd_init(void)
{
	/* Set up our internal device */
	spin_lock_init(&stackbd.lock);

	/* blk_alloc_queue() instead of blk_init_queue() so it won't set up the
     * queue for requests.
     */
    if (!(stackbd.queue = blk_alloc_queue(GFP_KERNEL)))
    {
        printk("stackbd: alloc_queue failed\n");
        return -EFAULT;
    }

    blk_queue_make_request(stackbd.queue, stackbd_make_request);
	blk_queue_logical_block_size(stackbd.queue, LOGICAL_BLOCK_SIZE);

	/* Get registered */
	if ((major_num = register_blkdev(major_num, STACKBD_NAME)) < 0)
    {
		printk("stackbd: unable to get major number\n");
		goto error_after_alloc_queue;
	}

	/* Gendisk structure */
	if (!(stackbd.gd = alloc_disk(16)))
		goto error_after_redister_blkdev;
	stackbd.gd->major = major_num;
	stackbd.gd->first_minor = 0;
	stackbd.gd->fops = &stackbd_ops;
	stackbd.gd->private_data = &stackbd;
	strcpy(stackbd.gd->disk_name, STACKBD_NAME_0);
	stackbd.gd->queue = stackbd.queue;
	add_disk(stackbd.gd);

    printk("stackbd: init done\n");

	return 0;

error_after_redister_blkdev:
	unregister_blkdev(major_num, STACKBD_NAME);
error_after_alloc_queue:
    blk_cleanup_queue(stackbd.queue);

	return -EFAULT;
}
示例#24
0
static int swim3_attach(struct macio_dev *mdev,
			const struct of_device_id *match)
{
	struct gendisk *disk;
	int index, rc;

	index = floppy_count++;
	if (index >= MAX_FLOPPIES)
		return -ENXIO;

	/* Add the drive */
	rc = swim3_add_device(mdev, index);
	if (rc)
		return rc;
	/* Now register that disk. Same comment about failure handling */
	disk = disks[index] = alloc_disk(1);
	if (disk == NULL)
		return -ENOMEM;
	disk->queue = blk_init_queue(do_fd_request, &swim3_lock);
	if (disk->queue == NULL) {
		put_disk(disk);
		return -ENOMEM;
	}
	blk_queue_bounce_limit(disk->queue, BLK_BOUNCE_HIGH);
	disk->queue->queuedata = &floppy_states[index];

	if (index == 0) {
		/* If we failed, there isn't much we can do as the driver is still
		 * too dumb to remove the device, just bail out
		 */
		if (register_blkdev(FLOPPY_MAJOR, "fd"))
			return 0;
	}

	disk->major = FLOPPY_MAJOR;
	disk->first_minor = index;
	disk->fops = &floppy_fops;
	disk->private_data = &floppy_states[index];
	disk->flags |= GENHD_FL_REMOVABLE;
	sprintf(disk->disk_name, "fd%d", index);
	set_capacity(disk, 2880);
	add_disk(disk);

	return 0;
}
示例#25
0
int init_module(void)
{
    int                result;



    printk(KERN_ALERT "ltpdev_init_module \n");

	ltp_pm_dev = pm_register(PM_UNKNOWN_DEV, 0, ltp_pm_callback);


    result = register_blkdev(ltp_fs_major, LTP_FS_DEV_NAME); 

    printk(KERN_ALERT "LTP FS: register_blkdev result=%d major %d\n",result, ltp_fs_major);

    if (result < 0) {
        printk(KERN_ALERT "LTP FS: can't get major %d\n",ltp_fs_major);
        return result;
    }

	gd_ptr = kmalloc(sizeof(struct gendisk *), GFP_KERNEL);

    if (!gd_ptr) {
        printk(KERN_ALERT "ERROR getting memory !!!\n");
        return 0;
    }

    gd_ptr = alloc_disk(1);

    printk(KERN_ALERT "gd_ptr after alloc = %p \n",gd_ptr);

    gd_ptr->major = ltp_fs_major;
    gd_ptr->first_minor = 0;
    gd_ptr->fops = &blkops;
    gd_ptr->driverfs_dev = NULL;
    gd_ptr->capacity = MAX_NUM_DISKS;
    gd_ptr->flags = genhd_flags;


    sprintf(gd_ptr->disk_name, LTP_FS_DEV_NAME);

    add_disk(gd_ptr);

    return 0;
}
示例#26
0
文件: zvol.c 项目: alek-p/zfs
/*
 * Allocate memory for a new zvol_state_t and setup the required
 * request queue and generic disk structures for the block device.
 */
static zvol_state_t *
zvol_alloc(dev_t dev, const char *name)
{
	zvol_state_t *zv;

	zv = kmem_zalloc(sizeof (zvol_state_t), KM_SLEEP);

	list_link_init(&zv->zv_next);

	zv->zv_queue = blk_alloc_queue(GFP_ATOMIC);
	if (zv->zv_queue == NULL)
		goto out_kmem;

	blk_queue_make_request(zv->zv_queue, zvol_request);
	blk_queue_set_write_cache(zv->zv_queue, B_TRUE, B_TRUE);

	zv->zv_disk = alloc_disk(ZVOL_MINORS);
	if (zv->zv_disk == NULL)
		goto out_queue;

	zv->zv_queue->queuedata = zv;
	zv->zv_dev = dev;
	zv->zv_open_count = 0;
	strlcpy(zv->zv_name, name, MAXNAMELEN);

	zfs_rlock_init(&zv->zv_range_lock);

	zv->zv_disk->major = zvol_major;
	zv->zv_disk->first_minor = (dev & MINORMASK);
	zv->zv_disk->fops = &zvol_ops;
	zv->zv_disk->private_data = zv;
	zv->zv_disk->queue = zv->zv_queue;
	snprintf(zv->zv_disk->disk_name, DISK_NAME_LEN, "%s%d",
	    ZVOL_DEV_NAME, (dev & MINORMASK));

	return (zv);

out_queue:
	blk_cleanup_queue(zv->zv_queue);
out_kmem:
	kmem_free(zv, sizeof (zvol_state_t));

	return (NULL);
}
示例#27
0
__kernel_dev_t _lkl_disk_add_disk(void *data, int sectors)
{
	struct lkl_disk_dev *dev;

	if (failed_init)
		return 0;

        if (!(dev=kzalloc(sizeof(*dev), GFP_KERNEL)))
		return 0;

        dev->data=data;

	spin_lock_init(&dev->lock);
	
        if (!(dev->queue=blk_init_queue(lkl_disk_request, &dev->lock))) {
		kfree(dev);
		return 0;
	}

	blk_queue_hardsect_size(dev->queue, 512);
	dev->queue->queuedata = dev;

	if (!(dev->gd=alloc_disk(1))) {
		kfree(dev);
		/* FIXME: del queue? */
		return 0;
	}

	dev->gd->major = major;
	dev->gd->first_minor = disks;
	dev->gd->fops = &lkl_disk_ops;
	dev->gd->queue = dev->queue;
	dev->gd->private_data = dev;
	snprintf (dev->gd->disk_name, 32, "lkldisk%d", disks);
	set_capacity(dev->gd, sectors);

	add_disk(dev->gd);

	disks++;

	printk("lkldisk: attached %s @ dev=%d:%d\n", dev->gd->disk_name, dev->gd->major, dev->gd->first_minor);

	return new_encode_dev(MKDEV(dev->gd->major, dev->gd->first_minor));
}
示例#28
0
/*
 * Allocate memory for a new zvol_state_t and setup the required
 * request queue and generic disk structures for the block device.
 */
static zvol_state_t *
zvol_alloc(dev_t dev, const char *name)
{
	zvol_state_t *zv;

	zv = kmem_zalloc(sizeof (zvol_state_t), KM_SLEEP);
	if (zv == NULL)
		goto out;

	zv->zv_queue = blk_init_queue(zvol_request, &zv->zv_lock);
	if (zv->zv_queue == NULL)
		goto out_kmem;

	zv->zv_disk = alloc_disk(ZVOL_MINORS);
	if (zv->zv_disk == NULL)
		goto out_queue;

	zv->zv_queue->queuedata = zv;
	zv->zv_dev = dev;
	zv->zv_open_count = 0;
	strlcpy(zv->zv_name, name, DISK_NAME_LEN);

	mutex_init(&zv->zv_znode.z_range_lock, NULL, MUTEX_DEFAULT, NULL);
	avl_create(&zv->zv_znode.z_range_avl, zfs_range_compare,
	    sizeof (rl_t), offsetof(rl_t, r_node));
	spin_lock_init(&zv->zv_lock);
	list_link_init(&zv->zv_next);

	zv->zv_disk->major = zvol_major;
	zv->zv_disk->first_minor = (dev & MINORMASK);
	zv->zv_disk->fops = &zvol_ops;
	zv->zv_disk->private_data = zv;
	zv->zv_disk->queue = zv->zv_queue;
	snprintf(zv->zv_disk->disk_name, DISK_NAME_LEN, "%s", name);

	return zv;

out_queue:
	blk_cleanup_queue(zv->zv_queue);
out_kmem:
	kmem_free(zv, sizeof (zvol_state_t));
out:
	return NULL;
}
示例#29
0
文件: swim3.c 项目: ANFS/ANFS-kernel
static int __devinit swim3_attach(struct macio_dev *mdev, const struct of_device_id *match)
{
	int i, rc;
	struct gendisk *disk;

	/* Add the drive */
	rc = swim3_add_device(mdev, floppy_count);
	if (rc)
		return rc;

	/* Now create the queue if not there yet */
	if (swim3_queue == NULL) {
		/* If we failed, there isn't much we can do as the driver is still
		 * too dumb to remove the device, just bail out
		 */
		if (register_blkdev(FLOPPY_MAJOR, "fd"))
			return 0;
		swim3_queue = blk_init_queue(do_fd_request, &swim3_lock);
		if (swim3_queue == NULL) {
			unregister_blkdev(FLOPPY_MAJOR, "fd");
			return 0;
		}
	}

	/* Now register that disk. Same comment about failure handling */
	i = floppy_count++;
	disk = disks[i] = alloc_disk(1);
	if (disk == NULL)
		return 0;

	disk->major = FLOPPY_MAJOR;
	disk->first_minor = i;
	disk->fops = &floppy_fops;
	disk->private_data = &floppy_states[i];
	disk->queue = swim3_queue;
	disk->flags |= GENHD_FL_REMOVABLE;
	sprintf(disk->disk_name, "fd%d", i);
	set_capacity(disk, 2880);
	add_disk(disk);

	return 0;
}
示例#30
0
static int sm_probe(struct device* dev)
{
    struct scsi_device *sdp = to_scsi_device(dev);
    int error = -ENODEV;

    if(sdp->type != TYPE_MEM)
        goto OUT;

    LogPath();
	struct gendisk* gd = NULL;
	gd = alloc_disk(1);
	if(!gd)
	{
		Log("[Error] alloc_disk failed.");
		return -1;
	}
	gd->major = SM_MAJOR;
	gd->first_minor = 0;
	gd->fops = &sm_fops;
	gd->private_data = sdp;
	sprintf(gd->disk_name,"sm-scsi");
	gd->queue = sdp->request_queue;
	gd->driverfs_dev = &sdp->sdev_gendev;
	//gd->flags = GENHD_FL_DRIVERFS;
	if(sdp->removable)
		gd->flags |= GENHD_FL_REMOVABLE;
	
	//dev->p->driver_data = (void*)gd;
	dev_set_drvdata(dev,(void*)gd);
	
	sm_spinup_mem_disk(sdp);
	sm_read_capacity(sdp);
	
	set_capacity(gd,g_mem_capacity >> 9);
	blk_queue_prep_rq(sdp->request_queue,sm_prep_fn);
	add_disk(gd);
	
	return 0;
OUT:
    return error;
}