Skip to contentSkip to conversation

Distributed storage release.

PATCH Evgeniy Polyakov 6 participants 11 messages Oct 6, 2008 – Oct 14, 2008

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

Hi.

I am pleased to announce new distributed storage (DST) project release.

DST is a block layer network device, which among others has following features:

* Kernel-side client and server. No need for any special tools for data processing (like special userspace applications) except for configuration.
* Bullet-proof memory allocations via memory pools for all temporary objects (transaction and so on).
* Zero-copy sending (except header) if supported by device using sendpage().
* Failover recovery in case of broken link
(reconnection if remote node is down).
* Full transaction support (resending of the failed transactions on timeout of after reconnect to failed node).
* Dynamically resizeable pool of threads used for data receiving and crypto processing.
* Initial autoconfiguration. Ability to extend it with additional attributes if needed.
* Support for any kind of network media (not limited to tcp or inet protocols) higher MAC layer (socket layer). Out of the box kernel-side IPv6 support (needs to extend configuration utility, check how it was done in POHMELFS [1]).
* Security attributes for local export nodes (list of allowed to connect addresses with permissions).
* Ability to use any supported cryptographically strong checksums. Ability to encrypt data channel.
* Keepalive messages to detect failed nodes early.

This release brings following changes:
* Keepalive messages to early detect failed nodes, which are sent if there is no traffic between the nodes.
* Listening socket reuses address now, which speeds up stop/start sequence.
* Fixed bug with wrong debug option, which could read uninitialized memory.
* Change module name from dst.ko to nst.ko, since the former is used by dvb card.
* Whitespace cleanup.

One can grab sources (various configuration examples can be found in 'userspace' dir) from archive, or via kernel and userspace GIT trees.

Consider for inclusion.
Thank you.

1. POHMELFS homepage.
http://tservice.net.ru/~s0mbre/old/?section=projects&item=pohmelfs

2. DST homepage.
http://tservice.net.ru/~s0mbre/old/?section=projects&item=dst

3. DST archive.
http://tservice.net.ru/~s0mbre/archive/dst/

4. DST git trees.
http://tservice.net.ru/~s0mbre/archive/dst/dst.git/
http://tservice.net.ru/~s0mbre/archive/dst/dst-userspace.git/

5. GIT web interface.
http://tservice.net.ru/~s0mbre/cgi-bin/gitweb.cgi

drivers/block/Kconfig +2 -0
index 0d1d213..56a64fe 100644
@@ -433,4 +433,6 @@ config VIRTIO_BLK
 	  This is the virtual block driver for virtio.  It can be used with
           lguest or QEMU based VMMs (like KVM or Xen).  Say Y or M.
 
+source "drivers/block/dst/Kconfig"
+
 endif # BLK_DEV
drivers/block/Makefile +2 -0
index 5e58430..26bcf8a 100644
@@ -31,3 +31,5 @@ obj-$(CONFIG_BLK_DEV_SX8)	+= sx8.o
 obj-$(CONFIG_BLK_DEV_UB)	+= ub.o
 
 obj-$(CONFIG_XEN_BLKDEV_FRONTEND)	+= xen-blkfront.o
+
+obj-$(CONFIG_DST)	+= dst/
drivers/block/dst/Kconfig new file +14 -0
new file mode 100644
index 0000000..2f42f98
@@ -0,0 +1,14 @@
+config DST
+	tristate "Distributed storage"
+	depends on NET
+	select CONNECTOR
+	select LIBCRC32C
+	---help---
+	This driver allows to create a distributed storage block device.
+
+config DST_DEBUG
+	bool "DST debug"
+	depends on DST
+	---help---
+	This option will turn HEAVY debugging of the DST.
+	Turn it on ONLY if you have to debug some really obscure problem.
drivers/block/dst/Makefile new file +3 -0
new file mode 100644
index 0000000..3a8b0cf
@@ -0,0 +1,3 @@
+obj-$(CONFIG_DST) += nst.o
+
+nst-y := dcore.o state.o export.o thread_pool.o crypto.o trans.o
drivers/block/dst/crypto.c new file +680 -0

680 lines not on this page · raw message

drivers/block/dst/dcore.c new file +879 -0

879 lines not on this page · raw message

drivers/block/dst/export.c new file +593 -0

593 lines not on this page · raw message

drivers/block/dst/state.c new file +784 -0

784 lines not on this page · raw message

drivers/block/dst/thread_pool.c new file +306 -0

36 lines not on this page · raw message

drivers/block/dst/trans.c new file +306 -0

306 lines not on this page · raw message

include/linux/connector.h +3 -1
index 96a89d3..cfc5ce7 100644

Lines of this file are not shown. View the raw message.

include/linux/dst.h new file +436 -0

436 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
	Evgeniy Polyakov

Part of the diff is not shown here. View the raw message.

#1 lore raw
Quoted 5 lines · On Mon, 6 Oct 2008 20:00:35 +0400 Evgeniy Polyakov <[email protected]> wrote:

Hi.

I am pleased to announce new distributed storage (DST) project release.

Please include diffstat with patches.

 drivers/block/Kconfig           |    2 
 drivers/block/Makefile          |    2 
 drivers/block/dst/Kconfig       |   14 
 drivers/block/dst/Makefile      |    3 
 drivers/block/dst/crypto.c      |  680 ++++++++++++++++++++++++++++++
 drivers/block/dst/dcore.c       |  879 ++++++++++++++++++++++++++++++++++++++++
 drivers/block/dst/export.c      |  593 ++++++++++++++++++++++++++
 drivers/block/dst/state.c       |  784 +++++++++++++++++++++++++++++++++++
 drivers/block/dst/thread_pool.c |  306 +++++++++++++
 drivers/block/dst/trans.c       |  306 +++++++++++++
 include/linux/connector.h       |    4 
 include/linux/dst.h             |  438 +++++++++++++++++++
 12 files changed, 4008 insertions(+), 3 deletions(-)

checkpatch says

total: 83 errors, 52 warnings, 4023 lines checked

many of which indeed should be fixed.

<scans the patch>

OK, I was going to spend an hour reviewing this patch but the almost total lack of useful comments means that this would be largely a waste of your time and of mine. I would need to read the implementation sufficiently closely to work out what it is setting out to do and I then would have to check whether it is doing it correctly.

Now I _could_ do that, although it would take a lot of time and the review would be less productive. But it would mean that the code is still hard to understand and hence hard to maitain. A much better outcome would be for you to properly document it. That will result in more efficient review, more effective review and better code.

No?

So please. Go through all the code and make it tell a story. Ask yourself "how would I explain all this to a kernel developer who is sitting next to me". It's important, and it's an important skill.

The means by which the code's memory allocation is "bulletproof" should be fully described in changelog comments so that those who are working on this sort of thing can check your homework, please.

I assume all this code adds some sort of userspace<->kernel interface. That should be documented in the kernel tree, so we can review it.

It would be good to document the on-the-wire protocol. That's an important thing.

Quoted 1 line

Some lightweight comments only:

Quoted 27 lines
drivers/block/Kconfig +2 -0
index 0d1d213..56a64fe 100644
@@ -433,4 +433,6 @@ config VIRTIO_BLK
 	  This is the virtual block driver for virtio.  It can be used with
           lguest or QEMU based VMMs (like KVM or Xen).  Say Y or M.
 
+source "drivers/block/dst/Kconfig"
+
 endif # BLK_DEV
drivers/block/Makefile +2 -0
index 5e58430..26bcf8a 100644
@@ -31,3 +31,5 @@ obj-$(CONFIG_BLK_DEV_SX8)	+= sx8.o
 obj-$(CONFIG_BLK_DEV_UB)	+= ub.o
 
 obj-$(CONFIG_XEN_BLKDEV_FRONTEND)	+= xen-blkfront.o
+
+obj-$(CONFIG_DST)	+= dst/
drivers/block/dst/Kconfig new file +0 -0
new file mode 100644
index 0000000..2f42f98

drivers/block/dst/Kconfig line 7

Quoted 7 lines
drivers/block/dst/Kconfig new file +7 -0
@@ -0,0 +1,14 @@
+config DST
+	tristate "Distributed storage"
+	depends on NET
+	select CONNECTOR
+	select LIBCRC32C
+	---help---
+	This driver allows to create a distributed storage block device.

depends on CRYPTO?

depends on BLOCK?

depends on SYSFS?

Quoted 24 lines
drivers/block/dst/Kconfig new file +6 -0
+config DST_DEBUG
+	bool "DST debug"
+	depends on DST
+	---help---
+	This option will turn HEAVY debugging of the DST.
+	Turn it on ONLY if you have to debug some really obscure problem.
drivers/block/dst/Makefile new file +10 -0
new file mode 100644
index 0000000..3a8b0cf
 
...
 
+static struct crypto_hash *dst_init_hash(struct dst_crypto_ctl *ctl, u8 *key)
+{
+	int err;
+	struct crypto_hash *hash;
+
+	hash = crypto_alloc_hash(ctl->hash_algo, 0, CRYPTO_ALG_ASYNC);
+	if (IS_ERR(hash)) {
+		err = PTR_ERR(hash);
+		dprintk("%s: failed to allocate hash '%s', err: %d.\n",
+				__func__, ctl->hash_algo, err);

drivers/block/dst/Makefile

Quoted 10 lines
drivers/block/dst/Makefile new file +10 -0
+		goto err_out_exit;
+	}
+
+	ctl->crypto_attached_size = crypto_hash_digestsize(hash);
+
+#if defined CONFIG_DST_DEBUG
+	dprintk("%s: keysize: %u, key: ", __func__, ctl->hash_keysize);
+	for (err = 0; err < ctl->hash_keysize; ++err)
+		printk("%02x ", key[err]);
+	printk("\n");

lib/hexdump.c?

Quoted 25 lines
drivers/block/dst/Makefile new file +22 -0
+#endif
+	if (!ctl->hash_keysize)
+		return hash;
+
+	err = crypto_hash_setkey(hash, key, ctl->hash_keysize);
+	if (err) {
+		dprintk("%s: failed to set key for hash '%s', err: %d.\n",
+				__func__, ctl->hash_algo, err);
+		goto err_out_free;
+	}
+
+	return hash;
+
+err_out_free:
+	crypto_free_hash(hash);
+err_out_exit:
+	return ERR_PTR(err);
+}
+
 
...
 
+static int dst_crypto_pages_alloc(struct dst_crypto_engine *e, int num)
+{
+	int i;

drivers/block/dst/Makefile

Quoted 10 lines
drivers/block/dst/Makefile new file +10 -0
+
+	e->pages = kmalloc(num * sizeof(struct page **), GFP_KERNEL);
+	if (!e->pages)
+		return -ENOMEM;
+
+	for (i=0; i<num; ++i) {
+		e->pages[i] = alloc_page(GFP_KERNEL);
+		if (!e->pages[i])
+			goto err_out_free_pages;
+	}

I wonder how many places in the kernel do the above. A little library function might be good.

Quoted 9 lines
drivers/block/dst/Makefile new file +9 -0
+	e->page_num = num;
+	return 0;
+
+err_out_free_pages:
+	while (--i >= 0)
+		__free_page(e->pages[i]);
+
+	kfree(e->pages);
+	return -ENOMEM;

drivers/block/dst/Makefile

Quoted 10 lines
drivers/block/dst/Makefile new file +7 -0
+}
+
 
...
 
+static int dst_crypto_process(struct ablkcipher_request *req,
+		struct scatterlist *sg_dst, struct scatterlist *sg_src,
+		void *iv, int enc, unsigned long timeout)
+{
+	struct dst_crypto_completion c;

hm. We have DECLARE_COMPLETION_ONSTACK (which is misnamed - it is a definition). That was created for some lockdep friendliness.

I expect that your on-stack completion here suffers from whatever problem DECLARE_COMPLETION_ONSTACK solved.

Quoted 36 lines
drivers/block/dst/Makefile new file +33 -0
+	int err;
+
+	init_completion(&c.complete);
+	c.error = -EINPROGRESS;
+
+	ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
+					dst_crypto_complete, &c);
+
+	ablkcipher_request_set_crypt(req, sg_src, sg_dst, sg_src->length, iv);
+
+	if (enc)
+		err = crypto_ablkcipher_encrypt(req);
+	else
+		err = crypto_ablkcipher_decrypt(req);
+
+	switch (err) {
+		case -EINPROGRESS:
+		case -EBUSY:
+			err = wait_for_completion_interruptible_timeout(&c.complete,
+					timeout);
+			if (!err)
+				err = -ETIMEDOUT;
+			else
+				err = c.error;
+			break;
+		default:
+			break;
+	}
+
+	return err;
+}
+
 
...
 
+static void *dst_crypto_thread_init(void *data)

drivers/block/dst/Makefile

Quoted 10 lines
drivers/block/dst/Makefile new file +10 -0
+{
+	struct dst_node *n = data;
+	struct dst_crypto_engine *e;
+	int err = -ENOMEM;
+
+	e = kzalloc(sizeof(struct dst_crypto_engine), GFP_KERNEL);
+	if (!e)
+		goto err_out_exit;
+	e->src = kzalloc(sizeof(struct scatterlist) * 2 * n->max_pages,
+			GFP_KERNEL);

kcalloc()?

Quoted 47 lines
drivers/block/dst/Makefile new file +44 -0
+	if (!e->src)
+		goto err_out_free;
+
+	e->dst = e->src + n->max_pages;
+
+	err = dst_crypto_engine_init(e, n);
+	if (err)
+		goto err_out_free_all;
+
+	return e;
+
+err_out_free_all:
+	kfree(e->src);
+err_out_free:
+	kfree(e);
+err_out_exit:
+	return ERR_PTR(err);
+}
+
 
...
 
+int dst_node_crypto_init(struct dst_node *n, struct dst_crypto_ctl *ctl)
+{
+	void *key = (ctl + 1);
+	int err = -ENOMEM, i;
+	char name[32];
+
+	if (ctl->hash_keysize) {
+		n->hash_key = kmalloc(ctl->hash_keysize, GFP_KERNEL);
+		if (!n->hash_key)
+			goto err_out_exit;
+		memcpy(n->hash_key, key, ctl->hash_keysize);
+	}
+
+	if (ctl->cipher_keysize) {
+		n->cipher_key = kmalloc(ctl->cipher_keysize, GFP_KERNEL);
+		if (!n->cipher_key)
+			goto err_out_free_hash;
+		memcpy(n->cipher_key, key, ctl->cipher_keysize);
+	}
+	memcpy(&n->crypto, ctl, sizeof(struct dst_crypto_ctl));
+
+	for (i=0; i<ctl->thread_num; ++i) {
+		snprintf(name, sizeof(name), "%s-crypto-%d", n->name, i);
+		/* Unique ids... */
+		err = thread_pool_add_worker(n->pool, name, i+10,

drivers/block/dst/Makefile

Quoted 10 lines
drivers/block/dst/Makefile new file +10 -0
+			dst_crypto_thread_init, dst_crypto_thread_cleanup, n);
+		if (err)
+			goto err_out_free_threads;
+	}
+
+	return 0;
+
+err_out_free_threads:
+	while (--i >= 0)
+		thread_pool_del_worker_id(n->pool, i+10);

Honestly man, how could you possibly have done that +10 thing without adding a comment explaining to poor readers what the heck it does?

Quoted 21 lines
drivers/block/dst/Makefile new file +18 -0
+	if (ctl->cipher_keysize)
+		kfree(n->cipher_key);
+	ctl->cipher_keysize = 0;
+err_out_free_hash:
+	if (ctl->hash_keysize)
+		kfree(n->hash_key);
+	ctl->hash_keysize = 0;
+err_out_exit:
+	return err;
+}
+
 
...
 
+static int dst_crypto_process_sending(struct dst_crypto_engine *e,
+		struct bio *bio, u8 *hash)
+{
+	int err;
+
+	if (e->cipher) {
+		err = dst_crypt(e, bio);

drivers/block/dst/Makefile

Quoted 10 lines
drivers/block/dst/Makefile new file +10 -0
+		if (err)
+			goto err_out_exit;
+	}
+
+	if (e->hash) {
+		err = dst_hash(e, bio, hash);
+		if (err)
+			goto err_out_exit;
+
+#if defined CONFIG_DST_DEBUG

We normally use #ifdef for the simple test.

Quoted 25 lines
drivers/block/dst/Makefile new file +22 -0
+		{
+			unsigned int i;
+
+			//dst_dump_bio(bio);
+
+			printk("%s: bio: %llu/%u, rw: %lu, hash: ",
+				__func__, (u64)bio->bi_sector,
+				bio->bi_size, bio_data_dir(bio));
+			for (i=0; i<crypto_hash_digestsize(e->hash); ++i)
+					printk("%02x ", hash[i]);
+			printk("\n");
+		}
+#endif
+	}
+
+	return 0;
+
+err_out_exit:
+	return err;
+}
+
 
...
 
+static int dst_export_crypto_action(void *crypto_engine, void *schedule_data)

drivers/block/dst/Makefile

Quoted 10 lines
drivers/block/dst/Makefile new file +10 -0
+{
+	struct dst_crypto_engine *e = crypto_engine;
+	struct bio *bio = schedule_data;
+	struct dst_export_priv *p = bio->bi_private;
+	int err;
+
+	dprintk("%s: e: %p, data: %p, bio: %llu/%u, dir: %lu.\n", __func__,
+		e, e->data, (u64)bio->bi_sector, bio->bi_size, bio_data_dir(bio));
+
+	e->enc = (bio_data_dir(bio) == READ);

Strange that something called "enc" is a boolean representing, umm whatever this represents. Please document each field in the data structures. THis realy helps.

Quoted 31 lines
drivers/block/dst/Makefile new file +29 -0
+	e->iv = p->cmd.id;
+
+	if (bio_data_dir(bio) == WRITE) {
+		u8 *hash = e->data + e->size/2;
+
+		err = dst_crypto_process_receiving(e, bio, hash, p->cmd.hash);
+		if (err)
+			goto err_out_exit;
+
+		generic_make_request(bio);
+	} else {
+		err = dst_crypto_process_sending(e, bio, p->cmd.hash);
+		if (err)
+			goto err_out_exit;
+
+		if (e->hash) {
+			p->cmd.csize = crypto_hash_digestsize(e->hash);
+			p->cmd.size += p->cmd.csize;
+		}
+
+		err = dst_export_send_bio(bio);
+	}
+	return 0;
+
+err_out_exit:
+	bio_put(bio);
+	return err;
+}
+
 
...

drivers/block/dst/Makefile

Quoted 10 lines
drivers/block/dst/Makefile new file +9 -0
 
+
+/*
+ * DST sysfs tree for device called 'storage':
+ *
+ * /sys/bus/dst/devices/storage/
+ * /sys/bus/dst/devices/storage/type : 192.168.4.80:1025
+ * /sys/bus/dst/devices/storage/size : 800
+ * /sys/bus/dst/devices/storage/name : storage
+ */

Documentation/ABI/, I guess.

drivers/block/dst/Makefile

Quoted 13 lines
drivers/block/dst/Makefile new file +13 -0
+static int dst_dev_match(struct device *dev, struct device_driver *drv)
+{
+	return 1;
+}
+
+static struct bus_type dst_dev_bus_type = {
+	.name 		= "dst",
+	.match 		= &dst_dev_match,
+};
+
+static void dst_node_release(struct device *dev)
+{
+}

Is that an empty release function? Does Documentation/kobject.txt apply? (search for "mocked mercilessly").

Quoted 9 lines
drivers/block/dst/Makefile new file +9 -0
+static struct device dst_node_dev = {
+	.bus 		= &dst_dev_bus_type,
+	.release 	= &dst_node_release
+};
+
+static void dst_node_set_size(struct dst_node *n)
+{
+	struct block_device *bdev;
+

drivers/block/dst/Makefile

Quoted 10 lines
drivers/block/dst/Makefile new file +10 -0
+	set_capacity(n->disk, n->size >> 9);
+
+	bdev = bdget_disk(n->disk, 0);
+	if (bdev) {
+		mutex_lock(&bdev->bd_inode->i_mutex);
+		i_size_write(bdev->bd_inode, n->size);
+		mutex_unlock(&bdev->bd_inode->i_mutex);
+		bdput(bdev);
+	}
+}

Should it do something if bdget() failed?

Quoted 27 lines
drivers/block/dst/Makefile new file +24 -0
+/*
+ * Distributed storage request processing function.
+ */
+static int dst_request(struct request_queue *q, struct bio *bio)
+{
+	struct dst_node *n = q->queuedata;
+
+	bio_get(bio);
+
+	return dst_process_bio(n, bio);
+}
+
 
...
 
+/*
+ * Block layer binding - disk is created when array is fully configured
+ * by userspace request.
+ */
+static int dst_node_create_disk(struct dst_node *n)
+{
+	int err = -ENOMEM;
+	u32 index = 0;
+
+	n->queue = blk_alloc_queue(GFP_KERNEL);
+	if (!n->queue)
+		goto err_out_exit;

drivers/block/dst/Makefile

Quoted 10 lines
drivers/block/dst/Makefile new file +10 -0
+
+	n->queue->queuedata = n;
+	blk_queue_make_request(n->queue, dst_request);
+	blk_queue_max_phys_segments(n->queue, n->max_pages);
+	blk_queue_max_hw_segments(n->queue, n->max_pages);
+
+	err = -EINVAL;
+	n->disk = alloc_disk(1);
+	if (!n->disk)
+		goto err_out_free_queue;

This should return -ENOMEM.

Quoted 51 lines
drivers/block/dst/Makefile new file +51 -0
+
+	if (!(n->state->permissions & DST_PERM_WRITE)) {
+		printk(KERN_INFO "DST node %s attached read-only.\n", n->name);
+		set_disk_ro(n->disk, 1);
+	}
+
+	err = -ENOMEM;
+	if (!idr_pre_get(&dst_index_idr, GFP_KERNEL))
+		goto err_out_put;
+
+	mutex_lock(&dst_hash_lock);
+	err = idr_get_new(&dst_index_idr, NULL, &index);
+	mutex_unlock(&dst_hash_lock);
+	if (err)
+		goto err_out_put;
+
+	n->disk->major = dst_major;
+	n->disk->first_minor = index;
+	n->disk->fops = &dst_blk_ops;
+	n->disk->queue = n->queue;
+	n->disk->private_data = n;
+	snprintf(n->disk->disk_name, sizeof(n->disk->disk_name), "dst-%s", n->name);
+
+	return 0;
+
+err_out_put:
+	put_disk(n->disk);
+err_out_free_queue:
+	blk_cleanup_queue(n->queue);
+err_out_exit:
+	return err;
+}
+
+static ssize_t dst_show_size(struct device *dev,
+		struct device_attribute *attr, char *buf)
+{
+	struct dst_node *n = container_of(dev, struct dst_node, device);
+
+	return sprintf(buf, "%llu\n", n->size);
+}
+
+/*
+ * Shows type of the remote node - device major/minor number
+ * for local nodes and address (af_inet ipv4/ipv6 only) for remote nodes.
+ */
+static ssize_t dst_show_type(struct device *dev,
+		struct device_attribute *attr, char *buf)
+{
+	struct dst_node *n = container_of(dev, struct dst_node, device);
+	struct sockaddr addr;
+	struct socket *sock;

drivers/block/dst/Makefile

Quoted 10 lines
drivers/block/dst/Makefile new file +10 -0
+	int addrlen;
+
+	sock = n->state->socket;
+	if (sock->ops->getname(sock, &addr, &addrlen, 2))
+		return 0;
+
+	if (sock->ops->family == AF_INET) {
+		struct sockaddr_in *sin = (struct sockaddr_in *)&addr;
+		return sprintf(buf, "%u.%u.%u.%u:%d\n",
+			NIPQUAD(sin->sin_addr.s_addr), ntohs(sin->sin_port));

hm, we still don't have a %p handler for ipv4 addresses.

Quoted 57 lines
drivers/block/dst/Makefile new file +54 -0
+	} else if (sock->ops->family == AF_INET6) {
+		struct sockaddr_in6 *sin = (struct sockaddr_in6 *)&addr;
+		return sprintf(buf,
+			"%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x:%d\n",
+			NIP6(sin->sin6_addr), ntohs(sin->sin6_port));
+	} else {
+		int i, sz = PAGE_SIZE - 2; /* 0 symbol and '\n' below */
+		int size;
+		unsigned char *a = (unsigned char *)&addr;
+		char *buf_orig = buf;
+
+		size = snprintf(buf, sz, "family: %d, addrlen: %u, addr: ",
+				addr.sa_family, addrlen);
+		sz -= size;
+		buf += size;
+
+		for (i=0; i<addrlen; ++i) {
+			if (sz < 3)
+				break;
+
+			size = snprintf(buf, sz, "%02x ", a[i]);
+			sz -= size;
+			buf += size;
+		}
+		buf += sprintf(buf, "\n");
+
+		return buf - buf_orig;
+	}
+	return 0;
+}
+
+static struct device_attribute dst_node_attrs[] = {
+	__ATTR(size, 0444, dst_show_size, NULL),
+	__ATTR(type, 0444, dst_show_type, NULL),
+};
+
 
...
 
+static void dst_node_cleanup(struct dst_node *n)
+{
+	struct dst_state *st = n->state;
+
+	if (!st)
+		return;
+
+	if (n->queue) {
+		blk_cleanup_queue(n->queue);
+
+		mutex_lock(&dst_hash_lock);
+		idr_remove(&dst_index_idr, n->disk->first_minor);
+		mutex_unlock(&dst_hash_lock);
+
+		put_disk(n->disk);
+	}
+
+	if (n->bdev) {

drivers/block/dst/Makefile

Quoted 10 lines
drivers/block/dst/Makefile new file +10 -0
+		sync_blockdev(n->bdev);
+		blkdev_put(n->bdev);
+	}
+
+	dst_state_lock(st);
+	st->need_exit = 1;
+	dst_state_exit_connected(st);
+	dst_state_unlock(st);
+
+	wake_up(&st->thread_wait);

Should we wait for them to all run and exit?

Quoted 24 lines
drivers/block/dst/Makefile new file +21 -0
+	dst_state_put(st);
+	n->state = NULL;
+}
+
 
...
 
+static int dst_setup_export(struct dst_node *n, struct dst_ctl *ctl,
+		struct dst_export_ctl *le)
+{
+	int err;
+	dev_t dev = 0; /* gcc likes to scream here */
+
+	err = dst_lookup_device(le->device, &dev);
+	if (err)
+		return err;
+
+	n->bdev = open_by_devnum(dev, FMODE_READ|FMODE_WRITE);
+	if (!n->bdev)
+		return -ENODEV;
+
+	if (n->size != 0)
+		n->size = min_t(loff_t, n->bdev->bd_inode->i_size, n->size);
+	else

drivers/block/dst/Makefile

Quoted 10 lines
drivers/block/dst/Makefile new file +10 -0
+		n->size = n->bdev->bd_inode->i_size;
+
+	err = dst_node_init_listened(n, le);
+	if (err)
+		goto err_out_cleanup;
+
+	return 0;
+
+err_out_cleanup:
+	sync_blockdev(n->bdev);

The sync_blockdev() is unexpected and needs a comment.

Quoted 5 lines
drivers/block/dst/Makefile new file +5 -0
+	blkdev_put(n->bdev);
+	n->bdev = NULL;
+
+	return err;
+}

drivers/block/dst/Makefile

Quoted 10 lines
drivers/block/dst/Makefile new file +7 -0
+
 
...
 
+static int __init dst_hashtable_init(void)
+{
+	unsigned int i;
+
+	dst_hashtable = kzalloc(sizeof(struct list_head) * dst_hashtable_size,
+			GFP_KERNEL);

kcalloc()?

Quoted 17 lines
drivers/block/dst/Makefile new file +17 -0
+	if (!dst_hashtable)
+		return -ENOMEM;
+
+	for (i=0; i<dst_hashtable_size; ++i)
+		INIT_LIST_HEAD(&dst_hashtable[i]);
+
+	return 0;
+}
+
+static void dst_hashtable_exit(void)
+{
+	unsigned int i;
+	struct dst_node *n, *tmp;
+
+	for (i=0; i<dst_hashtable_size; ++i) {
+		list_for_each_entry_safe(n, tmp, &dst_hashtable[i], node_entry) {
+			dst_node_remove_unload(n);

drivers/block/dst/Makefile

Quoted 10 lines
drivers/block/dst/Makefile new file +10 -0
+		}
+	}
+
+	kfree(dst_hashtable);
+}
+
+static int __init dst_sys_init(void)
+{
+	int err = -ENOMEM;
+	struct cb_id cn_dst_id = { CN_DST_IDX, CN_DST_VAL };

static?

Quoted 31 lines
drivers/block/dst/Makefile new file +31 -0
+	err = dst_hashtable_init();
+	if (err)
+		goto err_out_exit;
+
+	err = dst_export_init();
+	if (err)
+		goto err_out_hashtable_exit;
+
+	err = register_blkdev(dst_major, DST_NAME);
+	if (err < 0)
+		goto err_out_export_exit;
+	if (err)
+		dst_major = err;
+
+	err = dst_sysfs_init();
+	if (err)
+		goto err_out_unregister;
+
+	err = cn_add_callback(&cn_dst_id, "DST", cn_dst_callback);
+	if (err)
+		goto err_out_sysfs_exit;
+
+	printk(KERN_INFO "Distributed storage, '%s' release.\n", dst_name);
+
+	return 0;
+
+err_out_sysfs_exit:
+	dst_sysfs_exit();
+err_out_unregister:
+	unregister_blkdev(dst_major, DST_NAME);
+err_out_export_exit:

drivers/block/dst/Makefile

Quoted 10 lines
drivers/block/dst/Makefile new file +10 -0
+	dst_export_exit();
+err_out_hashtable_exit:
+	dst_hashtable_exit();
+err_out_exit:
+	return err;
+}
+
+static void __exit dst_sys_exit(void)
+{
+	struct cb_id cn_dst_id = { CN_DST_IDX, CN_DST_VAL };

Static?

Share with the above copy?

Quoted 34 lines
drivers/block/dst/Makefile new file +31 -0
+	cn_del_callback(&cn_dst_id);
+	unregister_blkdev(dst_major, DST_NAME);
+	dst_hashtable_exit();
+	dst_sysfs_exit();
+	dst_export_exit();
+}
+
 
...
 
+static struct dst_state *dst_accept_client(struct dst_state *st)
+{
+	unsigned int revents = 0;
+	unsigned int err_mask = POLLERR | POLLHUP | POLLRDHUP;
+	unsigned int mask = err_mask | POLLIN;
+	struct dst_node *n = st->node;
+	int err = 0;
+	struct socket *sock = NULL;
+	struct dst_state *new;
+
+	while (!err && !sock) {
+		revents = dst_state_poll(st);
+
+		if (!(revents & mask)) {
+			DEFINE_WAIT(wait);
+
+			for (;;) {
+				prepare_to_wait(&st->thread_wait,
+						&wait, TASK_INTERRUPTIBLE);
+				if (!n->trans_scan_timeout || st->need_exit)
+					break;
+
+				revents = dst_state_poll(st);
+

drivers/block/dst/Makefile

Quoted 10 lines
drivers/block/dst/Makefile new file +10 -0
+				if (revents & mask)
+					break;
+
+				if (signal_pending(current))
+					break;
+
+				schedule_timeout(HZ);
+			}
+			finish_wait(&st->thread_wait, &wait);
+		}

See, this unexpected one-second-polling thing is unexpected and there is no way on God's green earth that I can tell from the implementation why it was added and what problem it is solving.

Quoted 71 lines
drivers/block/dst/Makefile new file +68 -0
+		err = -ECONNRESET;
+		dst_state_lock(st);
+
+		dprintk("%s: st: %p, revents: %x [err: %d, in: %d].\n",
+			__func__, st, revents, revents & err_mask,
+			revents & POLLIN);
+
+		if (revents & err_mask) {
+			printk("%s: revents: %x, socket: %p, err: %d.\n",
+					__func__, revents, st->socket, err);
+			err = -ECONNRESET;
+		}
+
+		if (!n->trans_scan_timeout || st->need_exit)
+			err = -ENODEV;
+
+		if (st->socket && (revents & POLLIN))
+			err = kernel_accept(st->socket, &sock, 0);
+
+		dst_state_unlock(st);
+	}
+
+	if (err)
+		goto err_out_exit;
+
+	new = dst_state_alloc(st->node);
+	if (!new) {
+		err = -ENOMEM;
+		goto err_out_release;
+	}
+	new->socket = sock;
+
+	new->ctl.addr.sa_data_len = sizeof(struct sockaddr);
+	err = kernel_getpeername(sock, (struct sockaddr *)&new->ctl.addr,
+			(int *)&new->ctl.addr.sa_data_len);
+	if (err)
+		goto err_out_put;
+
+	new->permissions = dst_check_permissions(st, new);
+	if (new->permissions == 0) {
+		err = -EPERM;
+		dst_dump_addr(sock, (struct sockaddr *)&new->ctl.addr,
+				"Client is not allowed to connect");
+		goto err_out_put;
+	}
+
+	err = dst_poll_init(new);
+	if (err)
+		goto err_out_put;
+
+	dst_dump_addr(sock, (struct sockaddr *)&new->ctl.addr,
+			"Connected client");
+
+	return new;
+
+err_out_put:
+	dst_state_put(new);
+err_out_release:
+	sock_release(sock);
+err_out_exit:
+	return ERR_PTR(err);
+}
+
 
...
 
+static int dst_export_write_request(struct dst_state *st,
+		struct bio *bio, unsigned int total_size)
+{
+	unsigned int size;
+	struct page *page;

drivers/block/dst/Makefile

Quoted 10 lines
drivers/block/dst/Makefile new file +10 -0
+	void *data;
+	int err;
+
+	while (total_size) {
+		err = -ENOMEM;
+		page = alloc_page(GFP_KERNEL);
+		if (!page)
+			goto err_out_exit;
+
+		data = kmap(page);

There is never a need to kmap a GFP_KERNEL page.

kmap() is slow and deadlocky. kmap_atomic() is preferred.

drivers/block/dst/Makefile

Quoted 2 lines
drivers/block/dst/Makefile new file +2 -0
+		if (!data)
+			goto err_out_free_page;

kmap() cannot fail (see "deadlocky", above)

Quoted 19 lines
drivers/block/dst/Makefile new file +19 -0
+		size = min_t(unsigned int, PAGE_SIZE, total_size);
+
+		err = dst_data_recv(st, data, size);
+		if (err)
+			goto err_out_unmap_page;
+
+		err = bio_add_page(bio, page, size, 0);
+		if (err <= 0)
+			goto err_out_unmap_page;
+
+		kunmap(page);
+
+		total_size -= size;
+	}
+
+	return 0;
+
+err_out_unmap_page:
+	kunmap(page);

drivers/block/dst/Makefile

Quoted 10 lines
drivers/block/dst/Makefile new file +7 -0
+err_out_free_page:
+	__free_page(page);
+err_out_exit:
+	return err;
+}
+
 
...
 
+static void __inline__ dst_state_reset_nolock(struct dst_state *st)

s/__inline__/inline/g

drivers/block/dst/thread_pool.c

Quoted 10 lines
drivers/block/dst/Makefile new file +5 -0
+{
+	dst_state_exit_connected(st);
+	dst_state_init_connected(st);
+}
+
 
...
drivers/block/dst/thread_pool.c new file +0 -0

I don't think that any of this thread pool code is specific to this driver? It shouldn't be.

It would be much much better to present and review this as a separate standalone patch creating lib/thread_pool.c

drivers/block/dst/thread_pool.c

Quoted 9 lines

...

drivers/block/dst/thread_pool.c new file +6 -0
+static inline void dst_state_unlock(struct dst_state *st)
+{
+	BUG_ON(!mutex_is_locked(&st->state_lock));
+
+	mutex_unlock(&st->state_lock);
+}

surely lockdep or mutex debugging already warn about unlock of a not-locked mutex.

Casually adding debug stuff to an inlined function can cause rather a lot of bloat.

drivers/block/dst/thread_pool.c

Quoted 11 lines
drivers/block/dst/thread_pool.c new file +8 -0
+void dst_poll_exit(struct dst_state *st);
+int dst_poll_init(struct dst_state *st);
+
 
...
 
+static inline void dst_bio_to_cmd(struct bio *bio, struct dst_cmd *cmd,
+		u32 command, u64 id)
+{
+	cmd->cmd = command;
+	cmd->flags = (bio->bi_flags << BIO_POOL_BITS) >> BIO_POOL_BITS;

hm, strange. Appears to assume that no bits higher than those described by BIO_POOL_BITS will ever be used. That's fragile.

Quoted 7 lines
drivers/block/dst/thread_pool.c new file +7 -0
+	cmd->rw = bio->bi_rw;
+	cmd->size = bio->bi_size;
+	cmd->csize = 0;
+	cmd->id = id;
+	cmd->sector = bio->bi_sector;
+};
+

drivers/block/dst/thread_pool.c

Quoted 10 lines
drivers/block/dst/thread_pool.c new file +10 -0
+int dst_trans_send(struct dst_trans *t);
+int dst_trans_crypto(struct dst_trans *t);
+
+int dst_node_crypto_init(struct dst_node *n, struct dst_crypto_ctl *ctl);
+void dst_node_crypto_exit(struct dst_node *n);
+
+static inline int dst_need_crypto(struct dst_node *n)
+{
+	struct dst_crypto_ctl *c = &n->crypto;
+	return (c->hash_algo[0] || c->cipher_algo[0]);

Using single | might generate better code (but it'd need a comment explaining that it's a deliberate trick).

Or not do it - just a thought.

Quoted 5 lines
drivers/block/dst/thread_pool.c new file +2 -0
+}
+
 
...
#2 lore raw

Hi Andrew.

Quoted 1 line · Andrew Morton

Please include diffstat with patches.

Ok, will do.

Quoted 5 lines

checkpatch says

total: 83 errors, 52 warnings, 4023 lines checked

many of which indeed should be fixed.

There are two types of errors: long lines, which are actually comments on the same line as structure members or a little bit more than 80; and things like spaces and braces. All other errors should be already fixed, but stuff like this: for (i = 0; i < 10; ++i) are not, since we can argue forever if this is better than for (i=0; i<10; ++i) or int (* iterator) (struct dst_crypto_engine *e, vs
int (*iterator) (struct dst_crypto_engine *e,
:)
Also braces on the same line with the structure definition does not look good imho, and it is reported as error by checkpatch. Also found two previously missed trailing whitespaces, will fix them.

Quoted 6 lines

OK, I was going to spend an hour reviewing this patch but the almost total lack of useful comments means that this would be largely a waste of your time and of mine. I would need to read the implementation sufficiently closely to work out what it is setting out to do and I then would have to check whether it is doing it correctly.

Quoted 7 lines

Now I _could_ do that, although it would take a lot of time and the review would be less productive. But it would mean that the code is still hard to understand and hence hard to maitain. A much better outcome would be for you to properly document it. That will result in more efficient review, more effective review and better code.

No?

How much time did you spend reviewin it without comments? :)

Quoted 3 lines

So please. Go through all the code and make it tell a story. Ask yourself "how would I explain all this to a kernel developer who is sitting next to me". It's important, and it's an important skill.

Ok, I will add comments.

Quoted 3 lines

The means by which the code's memory allocation is "bulletproof" should be fully described in changelog comments so that those who are working on this sort of thing can check your homework, please.

Client uses only single additional allocation per request (comapred to fair number in device mapper for example) and it is made out of a memory pool. Network itself adds more, but block layer is quite optimal. Server works differently, since it has to have lots of pages to do IO, but again control structures (bio for example) are allocated from the memory pools. Besides that there are no additional allocations and preallocated buffers or page pools (for crypto processing) are used.

Quoted 2 lines

I assume all this code adds some sort of userspace<->kernel interface. That should be documented in the kernel tree, so we can review it.

It uses existing netlink connector interface, structures are partially documented though.

Quoted 2 lines

It would be good to document the on-the-wire protocol. That's an important thing.

Ok.

Quoted 12 lines

drivers/block/dst/Kconfig line 7

Quoted 9 lines

+++ b/drivers/block/dst/Kconfig

drivers/block/dst/Kconfig new file +7 -0
@@ -0,0 +1,14 @@
+config DST
+	tristate "Distributed storage"
+	depends on NET
+	select CONNECTOR
+	select LIBCRC32C
+	---help---
+	This driver allows to create a distributed storage block device.

depends on CRYPTO?

Quoted 3 lines

depends on BLOCK?

depends on SYSFS?

It depends on block by virtue of its config living in BLK_DEV submenu. It depends on sysfs though. I thought it already selected blkcipher, but apparently it does not, so dependency on crypto is also needed.

Quoted 7 lines

drivers/block/dst/crypto.c line 47

Quoted 5 lines
drivers/block/dst/crypto.c new file +5 -0
+#if defined CONFIG_DST_DEBUG
+	dprintk("%s: keysize: %u, key: ", __func__, ctl->hash_keysize);
+	for (err = 0; err < ctl->hash_keysize; ++err)
+		printk("%02x ", key[err]);
+	printk("\n");

lib/hexdump.c?

Yup, it can be used too.

Quoted 8 lines
Quoted 8 lines
drivers/block/dst/crypto.c new file +8 -0
+static int dst_crypto_pages_alloc(struct dst_crypto_engine *e, int num)
+{
+	int i;
+
+	e->pages = kmalloc(num * sizeof(struct page **), GFP_KERNEL);
+	if (!e->pages)
+		return -ENOMEM;
+
Quoted 8 lines

drivers/block/dst/crypto.c line 121

Quoted 5 lines
drivers/block/dst/crypto.c new file +5 -0
+	for (i=0; i<num; ++i) {
+		e->pages[i] = alloc_page(GFP_KERNEL);
+		if (!e->pages[i])
+			goto err_out_free_pages;
+	}

I wonder how many places in the kernel do the above. A little library function might be good.

Matter of a taste I think. Do you really want this to be in mm/mempolicy.c or around?

Quoted 11 lines

drivers/block/dst/crypto.c line 212

Quoted 5 lines
drivers/block/dst/crypto.c new file +5 -0
+static int dst_crypto_process(struct ablkcipher_request *req,
+		struct scatterlist *sg_dst, struct scatterlist *sg_src,
+		void *iv, int enc, unsigned long timeout)
+{
+	struct dst_crypto_completion c;

hm. We have DECLARE_COMPLETION_ONSTACK (which is misnamed - it is a definition). That was created for some lockdep friendliness.

I expect that your on-stack completion here suffers from whatever problem DECLARE_COMPLETION_ONSTACK solved.

Actually on-stack completions are everywhere, it is ok if they use dynamic initialization with init_completion() and not COMPLETION_INITIALIZER.

Quoted 5 lines
Quoted 5 lines
drivers/block/dst/crypto.c new file +5 -0
+static void *dst_crypto_thread_init(void *data)
+{
+	struct dst_node *n = data;
+	struct dst_crypto_engine *e;
+	int err = -ENOMEM;
Quoted 8 lines

drivers/block/dst/crypto.c line 356

Quoted 6 lines
drivers/block/dst/crypto.c new file +6 -0
+
+	e = kzalloc(sizeof(struct dst_crypto_engine), GFP_KERNEL);
+	if (!e)
+		goto err_out_exit;
+	e->src = kzalloc(sizeof(struct scatterlist) * 2 * n->max_pages,
+			GFP_KERNEL);

kcalloc()?

What's the difference? In saving one space and replacing another with comma? I do not particulary care, but would like to know why it is needed :)

Quoted 30 lines
Quoted 30 lines
drivers/block/dst/crypto.c new file +30 -0
+int dst_node_crypto_init(struct dst_node *n, struct dst_crypto_ctl *ctl)
+{
+	void *key = (ctl + 1);
+	int err = -ENOMEM, i;
+	char name[32];
+
+	if (ctl->hash_keysize) {
+		n->hash_key = kmalloc(ctl->hash_keysize, GFP_KERNEL);
+		if (!n->hash_key)
+			goto err_out_exit;
+		memcpy(n->hash_key, key, ctl->hash_keysize);
+	}
+
+	if (ctl->cipher_keysize) {
+		n->cipher_key = kmalloc(ctl->cipher_keysize, GFP_KERNEL);
+		if (!n->cipher_key)
+			goto err_out_free_hash;
+		memcpy(n->cipher_key, key, ctl->cipher_keysize);
+	}
+	memcpy(&n->crypto, ctl, sizeof(struct dst_crypto_ctl));
+
+	for (i=0; i<ctl->thread_num; ++i) {
+		snprintf(name, sizeof(name), "%s-crypto-%d", n->name, i);
+		/* Unique ids... */
+		err = thread_pool_add_worker(n->pool, name, i+10,
+			dst_crypto_thread_init, dst_crypto_thread_cleanup, n);
+		if (err)
+			goto err_out_free_threads;
+	}
+
Quoted 8 lines

drivers/block/dst/crypto.c line 419

Quoted 5 lines
drivers/block/dst/crypto.c new file +5 -0
+	return 0;
+
+err_out_free_threads:
+	while (--i >= 0)
+		thread_pool_del_worker_id(n->pool, i+10);

Honestly man, how could you possibly have done that +10 thing without adding a comment explaining to poor readers what the heck it does?

There is a comment above: Unique ids, zero is used by initial thread, so I added +10 :) It is not actually used iirc, but produce a nicer look in 'ps ax'.

Quoted 11 lines
Quoted 11 lines
drivers/block/dst/crypto.c new file +11 -0
+static int dst_crypto_process_sending(struct dst_crypto_engine *e,
+		struct bio *bio, u8 *hash)
+{
+	int err;
+
+	if (e->cipher) {
+		err = dst_crypt(e, bio);
+		if (err)
+			goto err_out_exit;
+	}
+
Quoted 8 lines

drivers/block/dst/crypto.c line 487

Quoted 6 lines
drivers/block/dst/crypto.c new file +6 -0
+	if (e->hash) {
+		err = dst_hash(e, bio, hash);
+		if (err)
+			goto err_out_exit;
+
+#if defined CONFIG_DST_DEBUG

We normally use #ifdef for the simple test.

Ok.

Quoted 7 lines
Quoted 7 lines
drivers/block/dst/crypto.c new file +7 -0
+static int dst_export_crypto_action(void *crypto_engine, void *schedule_data)
+{
+	struct dst_crypto_engine *e = crypto_engine;
+	struct bio *bio = schedule_data;
+	struct dst_export_priv *p = bio->bi_private;
+	int err;
+
Quoted 8 lines

drivers/block/dst/crypto.c line 635

Quoted 4 lines
drivers/block/dst/crypto.c new file +4 -0
+	dprintk("%s: e: %p, data: %p, bio: %llu/%u, dir: %lu.\n", __func__,
+		e, e->data, (u64)bio->bi_sector, bio->bi_size, bio_data_dir(bio));
+
+	e->enc = (bio_data_dir(bio) == READ);

Strange that something called "enc" is a boolean representing, umm whatever this represents. Please document each field in the data structures. THis realy helps.

It is encryption direction, it depends on IO direction and either it is performed on server or client, so may be confusing...

Quoted 10 lines
Quoted 8 lines

+/*
+ * DST sysfs tree for device called 'storage':
+ *
+ * /sys/bus/dst/devices/storage/
+ * /sys/bus/dst/devices/storage/type : 192.168.4.80:1025
+ * /sys/bus/dst/devices/storage/size : 800
+ * /sys/bus/dst/devices/storage/name : storage
+ */

Documentation/ABI/, I guess.

This is just a text info, do you really think it should be there?

Quoted 11 lines

drivers/block/dst/dcore.c line 67

Quoted 8 lines
drivers/block/dst/dcore.c new file +8 -0
+static struct bus_type dst_dev_bus_type = {
+	.name 		= "dst",
+	.match 		= &dst_dev_match,
+};
+
+static void dst_node_release(struct device *dev)
+{
+}

Is that an empty release function? Does Documentation/kobject.txt apply? (search for "mocked mercilessly").

Documentation lacks the case, when object is actually embedded into another one, which has appropriate reference counters and does not need kobject tree. So, before mocking one should think at least twice :)

Quoted 8 lines
Quoted 8 lines
drivers/block/dst/dcore.c new file +8 -0
+static void dst_node_set_size(struct dst_node *n)
+{
+	struct block_device *bdev;
+
+	set_capacity(n->disk, n->size >> 9);
+
+	bdev = bdget_disk(n->disk, 0);
+	if (bdev) {
Quoted 8 lines

drivers/block/dst/dcore.c line 87

Quoted 6 lines
drivers/block/dst/dcore.c new file +6 -0
+		mutex_lock(&bdev->bd_inode->i_mutex);
+		i_size_write(bdev->bd_inode, n->size);
+		mutex_unlock(&bdev->bd_inode->i_mutex);
+		bdput(bdev);
+	}
+}

Should it do something if bdget() failed?

First, it can not, since inode is being hold 'above' in the call stack, second, even if it fails in the parallel universe, size just is not updated and old one is used. Without this hunk run-time object size changes will not be noticed by for example filesystem and reading/writing will return EIO errors.

Quoted 16 lines
Quoted 16 lines
drivers/block/dst/dcore.c new file +16 -0
+/*
+ * Block layer binding - disk is created when array is fully configured
+ * by userspace request.
+ */
+static int dst_node_create_disk(struct dst_node *n)
+{
+	int err = -ENOMEM;
+	u32 index = 0;
+
+	n->queue = blk_alloc_queue(GFP_KERNEL);
+	if (!n->queue)
+		goto err_out_exit;
+
+	n->queue->queuedata = n;
+	blk_queue_make_request(n->queue, dst_request);
+	blk_queue_max_phys_segments(n->queue, n->max_pages);
Quoted 8 lines

drivers/block/dst/dcore.c line 144

Quoted 6 lines
drivers/block/dst/dcore.c new file +6 -0
+	blk_queue_max_hw_segments(n->queue, n->max_pages);
+
+	err = -EINVAL;
+	n->disk = alloc_disk(1);
+	if (!n->disk)
+		goto err_out_free_queue;

This should return -ENOMEM.

Yup.

Quoted 6 lines

drivers/block/dst/dcore.c line 205

Quoted 4 lines
drivers/block/dst/dcore.c new file +4 -0
+	if (sock->ops->family == AF_INET) {
+		struct sockaddr_in *sin = (struct sockaddr_in *)&addr;
+		return sprintf(buf, "%u.%u.%u.%u:%d\n",
+			NIPQUAD(sin->sin_addr.s_addr), ntohs(sin->sin_port));

hm, we still don't have a %p handler for ipv4 addresses.

:)

Quoted 22 lines
Quoted 22 lines
drivers/block/dst/dcore.c new file +22 -0
+static void dst_node_cleanup(struct dst_node *n)
+{
+	struct dst_state *st = n->state;
+
+	if (!st)
+		return;
+
+	if (n->queue) {
+		blk_cleanup_queue(n->queue);
+
+		mutex_lock(&dst_hash_lock);
+		idr_remove(&dst_index_idr, n->disk->first_minor);
+		mutex_unlock(&dst_hash_lock);
+
+		put_disk(n->disk);
+	}
+
+	if (n->bdev) {
+		sync_blockdev(n->bdev);
+		blkdev_put(n->bdev);
+	}
+
Quoted 8 lines

drivers/block/dst/dcore.c line 350

Quoted 6 lines
drivers/block/dst/dcore.c new file +6 -0
+	dst_state_lock(st);
+	st->need_exit = 1;
+	dst_state_exit_connected(st);
+	dst_state_unlock(st);
+
+	wake_up(&st->thread_wait);

Should we wait for them to all run and exit?

We will wait for threads in subsequent call to
thread_pool_destroy().

Quoted 21 lines
Quoted 21 lines
drivers/block/dst/dcore.c new file +21 -0
+static int dst_setup_export(struct dst_node *n, struct dst_ctl *ctl,
+		struct dst_export_ctl *le)
+{
+	int err;
+	dev_t dev = 0; /* gcc likes to scream here */
+
+	err = dst_lookup_device(le->device, &dev);
+	if (err)
+		return err;
+
+	n->bdev = open_by_devnum(dev, FMODE_READ|FMODE_WRITE);
+	if (!n->bdev)
+		return -ENODEV;
+
+	if (n->size != 0)
+		n->size = min_t(loff_t, n->bdev->bd_inode->i_size, n->size);
+	else
+		n->size = n->bdev->bd_inode->i_size;
+
+	err = dst_node_init_listened(n, le);
+	if (err)
Quoted 8 lines

drivers/block/dst/dcore.c line 449

Quoted 6 lines
drivers/block/dst/dcore.c new file +6 -0
+		goto err_out_cleanup;
+
+	return 0;
+
+err_out_cleanup:
+	sync_blockdev(n->bdev);

The sync_blockdev() is unexpected and needs a comment.

Copied from older code, when it was a call for release function, used both by just this open path and after disk registration and appropriate IO on it.

Quoted 9 lines
Quoted 9 lines
drivers/block/dst/dcore.c new file +6 -0
+	blkdev_put(n->bdev);
+	n->bdev = NULL;
+
+	return err;
+}
+
 
...
Quoted 8 lines

drivers/block/dst/dcore.c line 796

Quoted 6 lines
drivers/block/dst/dcore.c new file +6 -0
+static int __init dst_hashtable_init(void)
+{
+	unsigned int i;
+
+	dst_hashtable = kzalloc(sizeof(struct list_head) * dst_hashtable_size,
+			GFP_KERNEL);

kcalloc()?

To save a space? Ok :)

Quoted 7 lines

drivers/block/dst/dcore.c line 823

Quoted 4 lines
drivers/block/dst/dcore.c new file +4 -0
+static int __init dst_sys_init(void)
+{
+	int err = -ENOMEM;
+	struct cb_id cn_dst_id = { CN_DST_IDX, CN_DST_VAL };

static?

Quoted 7 lines

drivers/block/dst/dcore.c line 865

Quoted 3 lines
drivers/block/dst/dcore.c new file +3 -0
+static void __exit dst_sys_exit(void)
+{
+	struct cb_id cn_dst_id = { CN_DST_IDX, CN_DST_VAL };

Static?

Share with the above copy?

It could be...

Quoted 20 lines
Quoted 20 lines
drivers/block/dst/export.c new file +20 -0
+	while (!err && !sock) {
+		revents = dst_state_poll(st);
+
+		if (!(revents & mask)) {
+			DEFINE_WAIT(wait);
+
+			for (;;) {
+				prepare_to_wait(&st->thread_wait,
+						&wait, TASK_INTERRUPTIBLE);
+				if (!n->trans_scan_timeout || st->need_exit)
+					break;
+
+				revents = dst_state_poll(st);
+
+				if (revents & mask)
+					break;
+
+				if (signal_pending(current))
+					break;
+
Quoted 8 lines

drivers/block/dst/export.c line 116

Quoted 4 lines
drivers/block/dst/export.c new file +4 -0
+				schedule_timeout(HZ);
+			}
+			finish_wait(&st->thread_wait, &wait);
+		}

See, this unexpected one-second-polling thing is unexpected and there is no way on God's green earth that I can tell from the implementation why it was added and what problem it is solving.

It is used to check polling and exit flags. One can not add simple wakeup callbacks into network socket invalidation path, particulary socket can be marked closed in bottom half, so no mutex locking there. Actually I know, how network polling works and it can be accesed withuot locks _there_, but still there are places, where it can not, so I decided not to mess with different locks and just wakes once per timeout and check the polling flags.

Quoted 18 lines
Quoted 5 lines
drivers/block/dst/export.c new file +5 -0
+static int dst_export_write_request(struct dst_state *st,
+		struct bio *bio, unsigned int total_size)
+{
+	unsigned int size;
+	struct page *page;

drivers/block/dst/export.c line 444

Quoted 10 lines
drivers/block/dst/export.c new file +10 -0
+	void *data;
+	int err;
+
+	while (total_size) {
+		err = -ENOMEM;
+		page = alloc_page(GFP_KERNEL);
+		if (!page)
+			goto err_out_exit;
+
+		data = kmap(page);

There is never a need to kmap a GFP_KERNEL page.

Quoted 6 lines

kmap() is slow and deadlocky. kmap_atomic() is preferred.

drivers/block/dst/export.c line 446

Quoted 2 lines
drivers/block/dst/export.c new file +2 -0
+		if (!data)
+			goto err_out_free_page;

kmap() cannot fail (see "deadlocky", above)

kmap_atomic() can not be used here, since receiving path may sleep. This will not be a high mem, so no deadlocks.

Quoted 3 lines
Quoted 1 line

+static void __inline__ dst_state_reset_nolock(struct dst_state *st)

s/__inline__/inline/g

Ok. Why not plain 'inline'?

Quoted 8 lines

drivers/block/dst/thread_pool.c

Quoted 2 lines
drivers/block/dst/thread_pool.c new file +0 -0

I don't think that any of this thread pool code is specific to this driver? It shouldn't be.

It would be much much better to present and review this as a separate standalone patch creating lib/thread_pool.c

It is not driver-specific, but this means that DST project itself will have to depend on something else which will not be accepted upstream in a near future. I already have similar case for POHMELFS, where I just carry couple of export patches for VFS functions, and thus is not able to make it as external module.

lib/thread_pool.c is a good idea, but there will always be people who do not like it, I already lerned this kernel lesson. Spending days and days trying to create an ideal subsystem to match anyone's expectation about perfect interafaces and features jsut does not work, and kernel gets the patch from one, who is closer to the high end. I'm far from there, so will wait for perfect interface from anyone else and then convert DST if needed.

Quoted 10 lines

drivers/block/dst/thread_pool.c

Quoted 6 lines
drivers/block/dst/thread_pool.c new file +6 -0
+static inline void dst_state_unlock(struct dst_state *st)
+{
+	BUG_ON(!mutex_is_locked(&st->state_lock));
+
+	mutex_unlock(&st->state_lock);
+}

surely lockdep or mutex debugging already warn about unlock of a not-locked mutex.

Quoted 2 lines

Casually adding debug stuff to an inlined function can cause rather a lot of bloat.

Yup, I will remove it.

Quoted 6 lines
Quoted 6 lines
drivers/block/dst/thread_pool.c new file +3 -0
+void dst_poll_exit(struct dst_state *st);
+int dst_poll_init(struct dst_state *st);
+
 
...
Quoted 8 lines

drivers/block/dst/thread_pool.c

Quoted 5 lines
drivers/block/dst/thread_pool.c new file +5 -0
+static inline void dst_bio_to_cmd(struct bio *bio, struct dst_cmd *cmd,
+		u32 command, u64 id)
+{
+	cmd->cmd = command;
+	cmd->flags = (bio->bi_flags << BIO_POOL_BITS) >> BIO_POOL_BITS;

hm, strange. Appears to assume that no bits higher than those described by BIO_POOL_BITS will ever be used. That's fragile.

There is a comment for those bits in export.c where they are used :)

/*
* Server side is only interested in two low bits:
* uptodate (set by itself actually) and rw
* block
*/
bio->bi_flags |= cmd->flags & 3;

cmd->flags assignment actually clears bio pool bits, which are unused (server side can allocate bio from different pool, so it obviously should use own flags).

Quoted 9 lines

drivers/block/dst/thread_pool.c

Quoted 4 lines
drivers/block/dst/thread_pool.c new file +4 -0
+static inline int dst_need_crypto(struct dst_node *n)
+{
+	struct dst_crypto_ctl *c = &n->crypto;
+	return (c->hash_algo[0] || c->cipher_algo[0]);

Using single | might generate better code (but it'd need a comment explaining that it's a deliberate trick).

Or not do it - just a thought.

Getting that I have to write really lots of comments for this project, additional hunk will not hurt.

Thanks a lot for review, Andrew, I will work out issues you pointed and send updated version soon.

Signature · 1 line
	Evgeniy Polyakov
#3 lore raw

Hi Evgeniy,

Quoted 14 lines · Evgeniy Polyakov
Quoted 5 lines
Quoted 5 lines
drivers/block/dst/crypto.c new file +5 -0
+static void *dst_crypto_thread_init(void *data)
+{
+   struct dst_node *n = data;
+   struct dst_crypto_engine *e;
+   int err = -ENOMEM;
Quoted 8 lines

drivers/block/dst/crypto.c line 356

Quoted 6 lines
drivers/block/dst/crypto.c new file +6 -0
+
+   e = kzalloc(sizeof(struct dst_crypto_engine), GFP_KERNEL);
+   if (!e)
+           goto err_out_exit;
+   e->src = kzalloc(sizeof(struct scatterlist) * 2 * n->max_pages,
+                   GFP_KERNEL);

kcalloc()?

Quoted 3 lines

What's the difference? In saving one space and replacing another with comma? I do not particulary care, but would like to know why it is needed :)

kcalloc() will check for multiplication overflow which is nice especially if size is passed from user-space (not sure if that applies here).

#4 lore raw

Hi Pekka.

Quoted 7 lines · Pekka Enberg
Quoted 3 lines

What's the difference? In saving one space and replacing another with comma? I do not particulary care, but would like to know why it is needed :)

kcalloc() will check for multiplication overflow which is nice especially if size is passed from user-space (not sure if that applies here).

I think that 32-bit overflow check during multiplication in allocation code is the last thing to worry about :)
If this parameters are not checked before, we are screwd already...

P.S. DST does not check one of them, oops.

Signature · 1 line
	Evgeniy Polyakov
#5 lore raw
In reply to Evgeniy Polyakov
Quoted 10 lines · Evgeniy Polyakov

There are two types of errors: long lines, which are actually comments on the same line as structure members or a little bit more than 80; and things like spaces and braces. All other errors should be already fixed, but stuff like this: for (i = 0; i < 10; ++i) are not, since we can argue forever if this is better than for (i=0; i<10; ++i) or int (* iterator) (struct dst_crypto_engine *e, vs
int (*iterator) (struct dst_crypto_engine *e,
:)
Also braces on the same line with the structure definition does not look good imho, and it is reported as error by checkpatch.

While it is true that one coding style vs. another could be argued for a long time - the right answer is that the _right_ coding style for code added to the Linux kernel is Linus' CodingStyle document.

Whether you think the braces here or there look better - consistency with other code in the same project is very important, and any changes you get to your code will come in the Linus CodingStyle and this will result in code that is a mix between your personal style and the official style and it will be a mess...

Cheers, Andreas
--
Andreas Dilger
Sr. Staff Engineer, Lustre Group
Sun Microsystems of Canada, Inc.

#6 lore raw

Hi Andreas.

Quoted 9 lines · Andreas Dilger

While it is true that one coding style vs. another could be argued for a long time - the right answer is that the _right_ coding style for code added to the Linux kernel is Linus' CodingStyle document.

Whether you think the braces here or there look better - consistency with other code in the same project is very important, and any changes you get to your code will come in the Linus CodingStyle and this will result in code that is a mix between your personal style and the official style and it will be a mess...

Like Scsi_Host and include/scsi/scsi_host.h? My favourite coding style standards! It has the same space issues I have, but my code does not use capital letters :)

I always wondered... I submit almost 5 thousands line of code and I'm blamed that I do not have or have too many spaces in several dozens of lines. Should I get it as kernel hackers can not say anything bad about project except amount of spaces?

Btw, ext4 headers have the same issues with long lines as DST has. I'm pretty sure no one would notice that (as long as in DST) without checkpatch, which basically means that people do not care about the code.

Signature · 1 line
	Evgeniy Polyakov
#7 lore raw
Quoted 11 lines · Evgeniy Polyakov
Quoted 9 lines · Andreas Dilger

While it is true that one coding style vs. another could be argued for a long time - the right answer is that the _right_ coding style for code added to the Linux kernel is Linus' CodingStyle document.

Whether you think the braces here or there look better - consistency with other code in the same project is very important, and any changes you get to your code will come in the Linus CodingStyle and this will result in code that is a mix between your personal style and the official style and it will be a mess...

Quoted 3 lines

Like Scsi_Host and include/scsi/scsi_host.h? My favourite coding style standards! It has the same space issues I have, but my code does not use capital letters :)

I totally agree - this is a sign that in the past the kernel didn't follow the coding style closely enough and now we have a mishmash of code styles. That doesn't mean that new code should also contribute to that mess, but that old code should be cleaned up - as it is updated.

Quoted 4 lines

I always wondered... I submit almost 5 thousands line of code and I'm blamed that I do not have or have too many spaces in several dozens of lines. Should I get it as kernel hackers can not say anything bad about project except amount of spaces?

I was only commenting about your refusal to change the code style when Andrew asked it of you. There are good reasons to have a standard code style for large projects even if it isn't everyone's preferred style.

Cheers, Andreas
--
Andreas Dilger
Sr. Staff Engineer, Lustre Group
Sun Microsystems of Canada, Inc.

#8 lore raw
Quoted 8 lines · Andreas Dilger
Quoted 3 lines

Like Scsi_Host and include/scsi/scsi_host.h? My favourite coding style standards! It has the same space issues I have, but my code does not use capital letters :)

I totally agree - this is a sign that in the past the kernel didn't follow the coding style closely enough and now we have a mishmash of code styles. That doesn't mean that new code should also contribute to that mess, but that old code should be cleaned up - as it is updated.

Ext4 is a very new code :)
There are several lines which exceed 80 columns, which are actually comments, just what was blamed by the checkpatch.pl only. Really, no one cares about them.

Quoted 8 lines
Quoted 4 lines

I always wondered... I submit almost 5 thousands line of code and I'm blamed that I do not have or have too many spaces in several dozens of lines. Should I get it as kernel hackers can not say anything bad about project except amount of spaces?

I was only commenting about your refusal to change the code style when Andrew asked it of you. There are good reasons to have a standard code style for large projects even if it isn't everyone's preferred style.

That's what I meant :) Actually all other signs from The God of Checkpatch were sacrificed long ago, there are just several spaces and braces: let them be a small group of heathens at this religion time.

Standards are great, but killing a child just because he or she is left-hander, is a bit crazy, don't you think? So it would be quite interesting to hear that (at least one) showstopper for inclusion is a number of spaces :)

Of course this is stupid. Pointing to the ext4 with spaces is stupid. Taking care about what no one ever cares and make that to be a something significant is stupid. Making a religion out of checkpatch.pl output is actually great. As great as counting number of steps to the street corner and making that meaning of the life. Or at least a ground.

Signature · 1 line
	Evgeniy Polyakov
#9 lore raw
Quoted 4 lines · Evgeniy Polyakov

Standards are great, but killing a child just because he or she is left-hander, is a bit crazy, don't you think? So it would be quite interesting to hear that (at least one) showstopper for inclusion is a number of spaces :)

You're blowing this way out of proportion. Andrew said he'd be happy to do a better review of it if you documented it better, but until then all he could find time to do was a stylistic review.

Signature · 4 lines
Matthew Wilcox				Intel Open Source Technology Centre
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours.  We can't possibly take such
a retrograde step."
#10 lore raw

Hi Matthew.

Quoted 8 lines · Matthew Wilcox
Quoted 4 lines

Standards are great, but killing a child just because he or she is left-hander, is a bit crazy, don't you think? So it would be quite interesting to hear that (at least one) showstopper for inclusion is a number of spaces :)

You're blowing this way out of proportion. Andrew said he'd be happy to do a better review of it if you documented it better, but until then all he could find time to do was a stylistic review.

Are you absolutely sure we are talking here not about killed christian kids?

Didn't you accidentally miss that part, where I added documentation and released new version where 10% of the patch is code documentation in several hours :)

Essentially I resolved all comments Andrew made except checkpatch output and library functions which I asked if they are really needed. Even checkpatch output was cleaned (I removed long lines and added comments).

Signature · 1 line
	Evgeniy Polyakov