sheep: some macro preparation for sbd kernem modual

Reviewed-by: Robin Dong <sanbai@taobao.com>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
sbd: introduce basic framework for Sheepdog Block Device

This is similar to Ceph's RBD. The main motivation is to replace complex
and ineffecient middle ware (such as iscci softwafe) with simple software stacks
to expose sheepdog storage as Linux block device interface.

Usage:

We control the device the same way as RBD.

$ echo 127.0.0.1 7000 test > /sys/bus/sbd/add

$ echo 0 > /sys/bus/sbd/remove

For now we don't do actual read/write yet, just a aio framework sketched out.

Reviewed-by: Robin Dong <sanbai@taobao.com>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
sbd: implement write operation

- change the aio framework
  -- have submiter a dedicated kthread to avoid lockup
- flesh out sheep_handle_reply and sheep_aiocb_submit

Now we have two kthreads, one is for request submitting and the other is for
reply handling.

The tricky part is that sheep_submit_sdreq() will be called by both kthreads,
so we add a mutex to avoid send data intermingling, which would cause a very
tricky bug that sheep client will get wrong sd_req structure and reply with
very wrong sd_rsp.

The main problems for aio framework are,
- split the striding request into individual sheep requests for each objects.
- we only send one create request if object isn't created and block the requests
  to this object until the creation succeed then send the blocking requests.

To get best of performance,

Which means io scheduler will try its best to handle us 4MB request.

Reviewed-by: Robin Dong <sanbai@taobao.com>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
sbd: implement read operation

All we need to do is just handle off the response data back to bio.

Reviewed-by: Robin Dong <sanbai@taobao.com>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
sbd: add list interface to control file

This is meant to output the mapping between sbdX and sheep vdi.

The output looks like below.

root@vm1:/home/test/sheepdog/sbd# cat /sys/bus/sbd/list
0 test
1 disk1
2 disk2
3 disk3

Also add a mutex to make sbd add/remove/list thread safe.

Reviewed-by: Robin Dong <sanbai@taobao.com>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
sbd: add support for single major allocation scheme

Currently each sbd device is allocated its own major number, which leads to a
hard limit of 230-250 images mapped at once due to major_t is 12 bits.

This commit adds support for a new single-major device number allocation scheme,
meaning that we can make use of minor_t (20 bits) to map more images on a single
node.

For now we support 31 partitions for a sheep block device at most and 32768
devices for a single node.

The single major allocation looks like:

root@vm1:/home/test/sheepdog# cat /sys/bus/sbd/list
0 disk0  <--- sbd0
1 disk1
2 disk2

root@vm1:/home/test/sheepdog# ll /dev/sbd*
brw-rw---- 1 root disk 251,  0 May 24 20:27 /dev/sbd0
brw-rw---- 1 root disk 251,  1 May 24 20:27 /dev/sbd0p1 <-- partition 1 for sbd0
brw-rw---- 1 root disk 251,  2 May 24 20:27 /dev/sbd0p2 <-- partition 2 for sbd0
brw-rw---- 1 root disk 251,  3 May 24 20:27 /dev/sbd0p3 <-- partition 3 for sbd0
brw-rw---- 1 root disk 251, 32 May 24 20:28 /dev/sbd1
brw-rw---- 1 root disk 251, 33 May 24 20:28 /dev/sbd1p1
brw-rw---- 1 root disk 251, 34 May 24 20:28 /dev/sbd1p2
brw-rw---- 1 root disk 251, 64 May 24 20:22 /dev/sbd2

(major number 251 is dynamically genereged while insmod sbd.ko)

Reviewed-by: Robin Dong <sanbai@taobao.com>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
sbd: some error handling refinements

- switch sd_rsp->resault for sheep_run_sdreq
- explicitly handle some errors in sheep_handle_reply

We don't handle failure of submit_sheep_request yet. Make it a todo in the
future because auto-reconnect patch will hopefully solve the whole problem.

Also remove -DDEBUG

Reviewed-by: Robin Dong <sanbai@taobao.com>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
sbd: improve memory allocation when memory hit low

Let's try our best to allocate memory and make use of reserve memory to avoid
the memory allocation deadlock:

- when out of memory, ditry pages need to be written out, but need to allocate
memory for internal data structures to do the writeout.

PF_MEMALLOC and __GFP_MEMALLOC will try its best effort to allocate new memory.

Reviewed-by: Robin Dong <sanbai@taobao.com>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
sbd: use kmem_cache for sheep aiocb and request

Though it won't help the performance much, but let's do our best for performance

Reviewed-by: Robin Dong <sanbai@taobao.com>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>