static ssize_t disksize_store(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t len)
{
	int ret;
	u64 disksize;
	struct zram *zram = dev_to_zram(dev);

	ret = kstrtoull(buf, 10, &disksize);
	if (ret)
		return ret;

	down_write(&zram->init_lock);
	if (zram->init_done) {
		up_write(&zram->init_lock);
		pr_info("Cannot change disksize for initialized device\n");
		return -EBUSY;
	}

	zram->disksize = PAGE_ALIGN(disksize);
	set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT);
	up_write(&zram->init_lock);

	if (zram_init_device(zram) != 0) {
		printk(KERN_ALERT"\n\nzram_init_device failed!\n\n");
	}

	return len;
}
Exemplo n.º 2
0
static ssize_t disksize_store(struct device *dev,
		struct device_attribute *attr, const char *buf, size_t len)
{
	u64 disksize;
	struct zram_meta *meta;
	struct zram *zram = dev_to_zram(dev);

	disksize = memparse(buf, NULL);
	if (!disksize)
		return -EINVAL;

	disksize = PAGE_ALIGN(disksize);
	meta = zram_meta_alloc(disksize);
	down_write(&zram->init_lock);
	if (zram->init_done) {
		up_write(&zram->init_lock);
		zram_meta_free(meta);
		pr_info("Cannot change disksize for initialized device\n");
		return -EBUSY;
	}

	zram->disksize = disksize;
	set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT);
	zram_init_device(zram, meta);
	up_write(&zram->init_lock);

	return len;
}
Exemplo n.º 3
0
static ssize_t initstate_store(struct device *dev,
				struct device_attribute *attr, const char *buf,
				size_t len)
{
	int ret;
	unsigned long do_init;
	struct zram *zram = dev_to_zram(dev);

	if (zram->init_done) {
		pr_info("the device is initialized device\n");
		return -EBUSY;
	}

	ret = strict_strtoul(buf, 10, &do_init);
	if (ret)
		return ret;
	if (!do_init)
		return -EINVAL;

	zram_init_device(zram);
	swapon("/dev/block/zram0", 0);
	return len;
}