~ubuntu-branches/ubuntu/vivid/aufs/vivid

« back to all changes in this revision

Viewing changes to sample/uloop/00readme.txt

  • Committer: Bazaar Package Importer
  • Author(s): Julian Andres Klode
  • Date: 2007-12-15 23:32:51 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20071215233251-2vgs2lmg8mai5d9e
Tags: 0+20071211-1ubuntu1
* Merge from debian unstable (LP: #175705), remaining changes:
  - Fix for Ubuntu Kernels (updated)
* patches/01_vserver.dpatch: Removed
* patches/06_ubuntu.dpatch: Added (update of ubuntu patch)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
ULOOP -- Loopback block device in userspace
 
3
(and a sample for HTTP and generic block device)
 
4
Junjiro Okajima
 
5
 
 
6
# $Id: 00readme.txt,v 1.3 2007/11/26 01:35:40 sfjro Exp $
 
7
 
 
8
 
 
9
0. Introduction
 
10
As you know, there is a Loopback block device in Linux, /dev/loop,
 
11
which enables you to mount a fs-image local file.
 
12
Also it can adopt a userspace program, such as cryptloop.
 
13
This sample ULOOP driver makes it generic, and enables to adopt any
 
14
userspace program.
 
15
You can give an empty or non-existing file to /dev/loop backend.
 
16
When a process reads from /dev/loop, this dirver wakes a user process
 
17
up and passes the I/O transaction to it. A user process makes the
 
18
required block ready and tells the driver. Then the driver completes
 
19
the I/O transaction.
 
20
Also there is sample scripts or usage for diskless nodes working with
 
21
aufs. This driver may work with it well.
 
22
The name is unrelated to YouTube. :-)
 
23
 
 
24
 
 
25
1. libuloop API
 
26
- int ulo_init(struct ulo_init *init);
 
27
  struct ulo_init {
 
28
        char *path[ULO_Last];
 
29
        int dev_flags;
 
30
        unsigned long long size;
 
31
  };
 
32
  enum {ULO_DEV, ULO_CACHE, ULO_BITMAP, ULO_Last};
 
33
 
 
34
  Initializes ULOOP driver. All members in struct ulo_init must be set
 
35
  before you call ulo_init().
 
36
        + path[ULO_DEV]
 
37
          pathname of loopback device such as "/dev/loopN".
 
38
        + path[ULO_CACHE]
 
39
          pathname of a cache file. A userspace program stores the
 
40
          real data to this file.
 
41
        + path[ULO_BITMAP]
 
42
          pathname of a bitmap file. The ULOOP driver sets the bit
 
43
          which is corresponding the block number when the block is
 
44
          filled by a userspace program. When the bit is not set,
 
45
          ULOOP driver invokes the userspace program.
 
46
        + dev_flags
 
47
          Flags for open(2) of path[ULO_DEV].
 
48
        + size
 
49
          the size of real data. the ULOOP library set this size to
 
50
          the cache file after creating it internally.
 
51
 
 
52
- int ulo_loop(int sig, ulo_cb_t store, void *arg);
 
53
  typedef int (*ulo_cb_t)(unsigned long long start, int size, void *arg);
 
54
 
 
55
  Waits for a I/O request from ULOOP driver. When a user accesses a
 
56
  ULOOP device, ULOOP driver translates the request to the offset in
 
57
  the cache file and the requested size, and invokes the user-defined
 
58
  callback function which is specifed by `store.' The function `store'
 
59
  must fill the data in the cache file following the given offset and
 
60
  size. You can add an arugment `arg' for the callback function.
 
61
 
 
62
- extern const struct uloop *uloop;
 
63
  struct uloop {
 
64
        int fd[ULO_Last];
 
65
        int pagesize;
 
66
        unsigned long long tgt_size, cache_size;
 
67
  };
 
68
 
 
69
  A global variable in ULOOP library. Usually you will need
 
70
  'ulo_cache_fd` only. See below.
 
71
        #define ulo_dev_fd      ({ uloop->fd[ULO_DEV]; })
 
72
        #define ulo_cache_fd    ({ uloop->fd[ULO_CACHE]; })
 
73
        #define ulo_bitmap_fd   ({ uloop->fd[ULO_BITMAP]; })
 
74
 
 
75
 
 
76
2. sample for HTTP
 
77
Simple 'make' will build ./drivers/block/uloop.ko and ./ulohttp.
 
78
Ulohttp application behaves like losetup(8). Additionally, ulohttp is
 
79
an actual daemon which handles I/O request.
 
80
Here is a syntax.
 
81
 
 
82
ulohttp [-b bitmap] [-c cache] device URL
 
83
 
 
84
The device is /dev/loopN and the URL is a URL for fs-image file via
 
85
HTTP. The http server must support byte range (Range: header).
 
86
The bitmap is a new filename or previously specified as the bitmap for
 
87
the same URL. Its filesize will be 'the size of the specified fs-image
 
88
/ pagesize (usually 4k) / bits in a byte (8)', and round-up to
 
89
pagesize.
 
90
The cache is a new filename or previously specified as the cache for
 
91
the same URL. Its filesize will be 'the size of the specified
 
92
fs-image', and round-up to pagesize.
 
93
Note that both the bitmap and the cache are re-usable as long as you
 
94
don't change the filedata and URL.
 
95
 
 
96
When someone reads from the specified /dev/loopN, or accesses a file
 
97
on a filesystem after mounting /dev/loopN, ULOOP driver first checks
 
98
the corresponding bit in the bitmap file. When the bit is not set,
 
99
which means the block is not retreived yet, it passes the offset and
 
100
size of the I/O request to ulohttp daemon.
 
101
Ulohttp converts the offset and the size into HTTP GET request with
 
102
Range header and send it to the http server.
 
103
Retriving the data from the http server, ulohttp stores it to the
 
104
cache file, and tells ULOOP driver that the HTTP transfer completes.
 
105
Then the ULOOP driver sets the corresponding bit in the bitmap, and
 
106
finishes the I/O/request.
 
107
 
 
108
In other words, it is equivalent to this operation.
 
109
$ wget URL_for_fsimage
 
110
$ sudo mount -o loop retrieved_fsimage /mnt
 
111
But ULOOP driver and ulohttp retrives only the data (block) on-demand,
 
112
and stores into the cache file. The first access to a block is slow
 
113
since it involves HTTP GET, but the next access to the same block is
 
114
fast since it is in the local cache file. In this case, the behaviour
 
115
is equivalent to the simple /dev/loop device.
 
116
 
 
117
o Note
 
118
- ulohttp requires libcurl.
 
119
- ulohttp doesn't support HTTP PUT or POST, so the device rejects
 
120
  WRITE operation.
 
121
- ulohttp doesn't have a smart exit routine.
 
122
- This sample is "proof-of-concepts", do not expect the maturity level
 
123
  too much.
 
124
- This driver and the sample is developed and tested on linux-2.6.21.3.
 
125
- If you impelment other protocols such like nbd/enbd, iscsi, aoe or
 
126
  somehting, instead of http, I guess it will be fantastic. :-)
 
127
 
 
128
o Usage
 
129
$ make
 
130
$ sudo modprobe loop
 
131
$ sudo insmod ./drivers/block/uloop.ko
 
132
$ dev=/dev/loop7
 
133
$ ./ulohttp -b /tmp/b -c /tmp/c $dev http://whatever/you/like
 
134
$ sudo mount -o ro $dev /mnt
 
135
$ ls /mnt
 
136
        :::
 
137
$ sudo umount /mnt
 
138
$ killall ulohttp
 
139
$ sudo losetup -d $dev
 
140
 
 
141
 
 
142
3. sample for generic block device
 
143
The sample `ulohttp' (above) retrives data from a remote host via
 
144
HTTP, and stores it into a local file as a cache. It means you can
 
145
reduce the network traffic and the workload on a remote server.
 
146
As you can guess easily, this scheme is also effective to a local disk
 
147
device, espcially when you want to make your disk and spin down/off
 
148
it. Recent flash memory is getting larger and cheaper. You can cache
 
149
the whole contents of your harddirve into a file on your flash.
 
150
Here is a sample for it, `ulobdev.' The basic usage is very similar to
 
151
`ulohttp'. See above.
 
152
Of course, it is available for remote block devices too, such as
 
153
nbd/enbd, iscsi and aoe.
 
154
 
 
155
You should not mount the backend block device as readwrite, since it
 
156
modifies the superblock of the filesystem on the block device even if
 
157
youu don't write anything to it.
 
158
 
 
159
Currently this sample supports readonly mode only.
 
160
If someone is interested in this approach and sample, I will add some
 
161
features which will support read/write mode and write-back to the
 
162
harddrive periodically, and discard/re-create the cache file.
 
163
 
 
164
 
 
165
Enjoy!