ubd_kern.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399
  1. /*
  2. * Copyright (C) 2000 Jeff Dike (jdike@karaya.com)
  3. * Licensed under the GPL
  4. */
  5. /* 2001-09-28...2002-04-17
  6. * Partition stuff by James_McMechan@hotmail.com
  7. * old style ubd by setting UBD_SHIFT to 0
  8. * 2002-09-27...2002-10-18 massive tinkering for 2.5
  9. * partitions have changed in 2.5
  10. * 2003-01-29 more tinkering for 2.5.59-1
  11. * This should now address the sysfs problems and has
  12. * the symlink for devfs to allow for booting with
  13. * the common /dev/ubd/discX/... names rather than
  14. * only /dev/ubdN/discN this version also has lots of
  15. * clean ups preparing for ubd-many.
  16. * James McMechan
  17. */
  18. #define MAJOR_NR UBD_MAJOR
  19. #define UBD_SHIFT 4
  20. #include "linux/config.h"
  21. #include "linux/module.h"
  22. #include "linux/blkdev.h"
  23. #include "linux/hdreg.h"
  24. #include "linux/init.h"
  25. #include "linux/cdrom.h"
  26. #include "linux/proc_fs.h"
  27. #include "linux/ctype.h"
  28. #include "linux/capability.h"
  29. #include "linux/mm.h"
  30. #include "linux/vmalloc.h"
  31. #include "linux/blkpg.h"
  32. #include "linux/genhd.h"
  33. #include "linux/spinlock.h"
  34. #include "linux/platform_device.h"
  35. #include "asm/segment.h"
  36. #include "asm/uaccess.h"
  37. #include "asm/irq.h"
  38. #include "asm/types.h"
  39. #include "asm/tlbflush.h"
  40. #include "user_util.h"
  41. #include "mem_user.h"
  42. #include "kern_util.h"
  43. #include "kern.h"
  44. #include "mconsole_kern.h"
  45. #include "init.h"
  46. #include "irq_user.h"
  47. #include "irq_kern.h"
  48. #include "ubd_user.h"
  49. #include "os.h"
  50. #include "mem.h"
  51. #include "mem_kern.h"
  52. #include "cow.h"
  53. enum ubd_req { UBD_READ, UBD_WRITE };
  54. struct io_thread_req {
  55. enum ubd_req op;
  56. int fds[2];
  57. unsigned long offsets[2];
  58. unsigned long long offset;
  59. unsigned long length;
  60. char *buffer;
  61. int sectorsize;
  62. unsigned long sector_mask;
  63. unsigned long long cow_offset;
  64. unsigned long bitmap_words[2];
  65. int error;
  66. };
  67. extern int open_ubd_file(char *file, struct openflags *openflags, int shared,
  68. char **backing_file_out, int *bitmap_offset_out,
  69. unsigned long *bitmap_len_out, int *data_offset_out,
  70. int *create_cow_out);
  71. extern int create_cow_file(char *cow_file, char *backing_file,
  72. struct openflags flags, int sectorsize,
  73. int alignment, int *bitmap_offset_out,
  74. unsigned long *bitmap_len_out,
  75. int *data_offset_out);
  76. extern int read_cow_bitmap(int fd, void *buf, int offset, int len);
  77. extern void do_io(struct io_thread_req *req);
  78. static inline int ubd_test_bit(__u64 bit, unsigned char *data)
  79. {
  80. __u64 n;
  81. int bits, off;
  82. bits = sizeof(data[0]) * 8;
  83. n = bit / bits;
  84. off = bit % bits;
  85. return((data[n] & (1 << off)) != 0);
  86. }
  87. static inline void ubd_set_bit(__u64 bit, unsigned char *data)
  88. {
  89. __u64 n;
  90. int bits, off;
  91. bits = sizeof(data[0]) * 8;
  92. n = bit / bits;
  93. off = bit % bits;
  94. data[n] |= (1 << off);
  95. }
  96. /*End stuff from ubd_user.h*/
  97. #define DRIVER_NAME "uml-blkdev"
  98. static DEFINE_SPINLOCK(ubd_io_lock);
  99. static DEFINE_SPINLOCK(ubd_lock);
  100. static void (*do_ubd)(void);
  101. static int ubd_open(struct inode * inode, struct file * filp);
  102. static int ubd_release(struct inode * inode, struct file * file);
  103. static int ubd_ioctl(struct inode * inode, struct file * file,
  104. unsigned int cmd, unsigned long arg);
  105. static int ubd_getgeo(struct block_device *bdev, struct hd_geometry *geo);
  106. #define MAX_DEV (8)
  107. static struct block_device_operations ubd_blops = {
  108. .owner = THIS_MODULE,
  109. .open = ubd_open,
  110. .release = ubd_release,
  111. .ioctl = ubd_ioctl,
  112. .getgeo = ubd_getgeo,
  113. };
  114. /* Protected by the queue_lock */
  115. static request_queue_t *ubd_queue;
  116. /* Protected by ubd_lock */
  117. static int fake_major = MAJOR_NR;
  118. static struct gendisk *ubd_gendisk[MAX_DEV];
  119. static struct gendisk *fake_gendisk[MAX_DEV];
  120. #ifdef CONFIG_BLK_DEV_UBD_SYNC
  121. #define OPEN_FLAGS ((struct openflags) { .r = 1, .w = 1, .s = 1, .c = 0, \
  122. .cl = 1 })
  123. #else
  124. #define OPEN_FLAGS ((struct openflags) { .r = 1, .w = 1, .s = 0, .c = 0, \
  125. .cl = 1 })
  126. #endif
  127. /* Not protected - changed only in ubd_setup_common and then only to
  128. * to enable O_SYNC.
  129. */
  130. static struct openflags global_openflags = OPEN_FLAGS;
  131. struct cow {
  132. /* This is the backing file, actually */
  133. char *file;
  134. int fd;
  135. unsigned long *bitmap;
  136. unsigned long bitmap_len;
  137. int bitmap_offset;
  138. int data_offset;
  139. };
  140. struct ubd {
  141. char *file;
  142. int count;
  143. int fd;
  144. __u64 size;
  145. struct openflags boot_openflags;
  146. struct openflags openflags;
  147. int shared;
  148. int no_cow;
  149. struct cow cow;
  150. struct platform_device pdev;
  151. };
  152. #define DEFAULT_COW { \
  153. .file = NULL, \
  154. .fd = -1, \
  155. .bitmap = NULL, \
  156. .bitmap_offset = 0, \
  157. .data_offset = 0, \
  158. }
  159. #define DEFAULT_UBD { \
  160. .file = NULL, \
  161. .count = 0, \
  162. .fd = -1, \
  163. .size = -1, \
  164. .boot_openflags = OPEN_FLAGS, \
  165. .openflags = OPEN_FLAGS, \
  166. .no_cow = 0, \
  167. .shared = 0, \
  168. .cow = DEFAULT_COW, \
  169. }
  170. struct ubd ubd_dev[MAX_DEV] = { [ 0 ... MAX_DEV - 1 ] = DEFAULT_UBD };
  171. static int ubd0_init(void)
  172. {
  173. struct ubd *dev = &ubd_dev[0];
  174. if(dev->file == NULL)
  175. dev->file = "root_fs";
  176. return(0);
  177. }
  178. __initcall(ubd0_init);
  179. /* Only changed by fake_ide_setup which is a setup */
  180. static int fake_ide = 0;
  181. static struct proc_dir_entry *proc_ide_root = NULL;
  182. static struct proc_dir_entry *proc_ide = NULL;
  183. static void make_proc_ide(void)
  184. {
  185. proc_ide_root = proc_mkdir("ide", NULL);
  186. proc_ide = proc_mkdir("ide0", proc_ide_root);
  187. }
  188. static int proc_ide_read_media(char *page, char **start, off_t off, int count,
  189. int *eof, void *data)
  190. {
  191. int len;
  192. strcpy(page, "disk\n");
  193. len = strlen("disk\n");
  194. len -= off;
  195. if (len < count){
  196. *eof = 1;
  197. if (len <= 0) return 0;
  198. }
  199. else len = count;
  200. *start = page + off;
  201. return len;
  202. }
  203. static void make_ide_entries(char *dev_name)
  204. {
  205. struct proc_dir_entry *dir, *ent;
  206. char name[64];
  207. if(proc_ide_root == NULL) make_proc_ide();
  208. dir = proc_mkdir(dev_name, proc_ide);
  209. if(!dir) return;
  210. ent = create_proc_entry("media", S_IFREG|S_IRUGO, dir);
  211. if(!ent) return;
  212. ent->nlink = 1;
  213. ent->data = NULL;
  214. ent->read_proc = proc_ide_read_media;
  215. ent->write_proc = NULL;
  216. sprintf(name,"ide0/%s", dev_name);
  217. proc_symlink(dev_name, proc_ide_root, name);
  218. }
  219. static int fake_ide_setup(char *str)
  220. {
  221. fake_ide = 1;
  222. return(1);
  223. }
  224. __setup("fake_ide", fake_ide_setup);
  225. __uml_help(fake_ide_setup,
  226. "fake_ide\n"
  227. " Create ide0 entries that map onto ubd devices.\n\n"
  228. );
  229. static int parse_unit(char **ptr)
  230. {
  231. char *str = *ptr, *end;
  232. int n = -1;
  233. if(isdigit(*str)) {
  234. n = simple_strtoul(str, &end, 0);
  235. if(end == str)
  236. return(-1);
  237. *ptr = end;
  238. }
  239. else if (('a' <= *str) && (*str <= 'h')) {
  240. n = *str - 'a';
  241. str++;
  242. *ptr = str;
  243. }
  244. return(n);
  245. }
  246. static int ubd_setup_common(char *str, int *index_out)
  247. {
  248. struct ubd *dev;
  249. struct openflags flags = global_openflags;
  250. char *backing_file;
  251. int n, err, i;
  252. if(index_out) *index_out = -1;
  253. n = *str;
  254. if(n == '='){
  255. char *end;
  256. int major;
  257. str++;
  258. if(!strcmp(str, "sync")){
  259. global_openflags = of_sync(global_openflags);
  260. return(0);
  261. }
  262. major = simple_strtoul(str, &end, 0);
  263. if((*end != '\0') || (end == str)){
  264. printk(KERN_ERR
  265. "ubd_setup : didn't parse major number\n");
  266. return(1);
  267. }
  268. err = 1;
  269. spin_lock(&ubd_lock);
  270. if(fake_major != MAJOR_NR){
  271. printk(KERN_ERR "Can't assign a fake major twice\n");
  272. goto out1;
  273. }
  274. fake_major = major;
  275. printk(KERN_INFO "Setting extra ubd major number to %d\n",
  276. major);
  277. err = 0;
  278. out1:
  279. spin_unlock(&ubd_lock);
  280. return(err);
  281. }
  282. n = parse_unit(&str);
  283. if(n < 0){
  284. printk(KERN_ERR "ubd_setup : couldn't parse unit number "
  285. "'%s'\n", str);
  286. return(1);
  287. }
  288. if(n >= MAX_DEV){
  289. printk(KERN_ERR "ubd_setup : index %d out of range "
  290. "(%d devices, from 0 to %d)\n", n, MAX_DEV, MAX_DEV - 1);
  291. return(1);
  292. }
  293. err = 1;
  294. spin_lock(&ubd_lock);
  295. dev = &ubd_dev[n];
  296. if(dev->file != NULL){
  297. printk(KERN_ERR "ubd_setup : device already configured\n");
  298. goto out;
  299. }
  300. if (index_out)
  301. *index_out = n;
  302. for (i = 0; i < sizeof("rscd="); i++) {
  303. switch (*str) {
  304. case 'r':
  305. flags.w = 0;
  306. break;
  307. case 's':
  308. flags.s = 1;
  309. break;
  310. case 'd':
  311. dev->no_cow = 1;
  312. break;
  313. case 'c':
  314. dev->shared = 1;
  315. break;
  316. case '=':
  317. str++;
  318. goto break_loop;
  319. default:
  320. printk(KERN_ERR "ubd_setup : Expected '=' or flag letter (r, s, c, or d)\n");
  321. goto out;
  322. }
  323. str++;
  324. }
  325. if (*str == '=')
  326. printk(KERN_ERR "ubd_setup : Too many flags specified\n");
  327. else
  328. printk(KERN_ERR "ubd_setup : Expected '='\n");
  329. goto out;
  330. break_loop:
  331. err = 0;
  332. backing_file = strchr(str, ',');
  333. if (!backing_file) {
  334. backing_file = strchr(str, ':');
  335. }
  336. if(backing_file){
  337. if(dev->no_cow)
  338. printk(KERN_ERR "Can't specify both 'd' and a "
  339. "cow file\n");
  340. else {
  341. *backing_file = '\0';
  342. backing_file++;
  343. }
  344. }
  345. dev->file = str;
  346. dev->cow.file = backing_file;
  347. dev->boot_openflags = flags;
  348. out:
  349. spin_unlock(&ubd_lock);
  350. return(err);
  351. }
  352. static int ubd_setup(char *str)
  353. {
  354. ubd_setup_common(str, NULL);
  355. return(1);
  356. }
  357. __setup("ubd", ubd_setup);
  358. __uml_help(ubd_setup,
  359. "ubd<n><flags>=<filename>[(:|,)<filename2>]\n"
  360. " This is used to associate a device with a file in the underlying\n"
  361. " filesystem. When specifying two filenames, the first one is the\n"
  362. " COW name and the second is the backing file name. As separator you can\n"
  363. " use either a ':' or a ',': the first one allows writing things like;\n"
  364. " ubd0=~/Uml/root_cow:~/Uml/root_backing_file\n"
  365. " while with a ',' the shell would not expand the 2nd '~'.\n"
  366. " When using only one filename, UML will detect whether to thread it like\n"
  367. " a COW file or a backing file. To override this detection, add the 'd'\n"
  368. " flag:\n"
  369. " ubd0d=BackingFile\n"
  370. " Usually, there is a filesystem in the file, but \n"
  371. " that's not required. Swap devices containing swap files can be\n"
  372. " specified like this. Also, a file which doesn't contain a\n"
  373. " filesystem can have its contents read in the virtual \n"
  374. " machine by running 'dd' on the device. <n> must be in the range\n"
  375. " 0 to 7. Appending an 'r' to the number will cause that device\n"
  376. " to be mounted read-only. For example ubd1r=./ext_fs. Appending\n"
  377. " an 's' will cause data to be written to disk on the host immediately.\n\n"
  378. );
  379. static int udb_setup(char *str)
  380. {
  381. printk("udb%s specified on command line is almost certainly a ubd -> "
  382. "udb TYPO\n", str);
  383. return(1);
  384. }
  385. __setup("udb", udb_setup);
  386. __uml_help(udb_setup,
  387. "udb\n"
  388. " This option is here solely to catch ubd -> udb typos, which can be\n"
  389. " to impossible to catch visually unless you specifically look for\n"
  390. " them. The only result of any option starting with 'udb' is an error\n"
  391. " in the boot output.\n\n"
  392. );
  393. static int fakehd_set = 0;
  394. static int fakehd(char *str)
  395. {
  396. printk(KERN_INFO "fakehd : Changing ubd name to \"hd\".\n");
  397. fakehd_set = 1;
  398. return 1;
  399. }
  400. __setup("fakehd", fakehd);
  401. __uml_help(fakehd,
  402. "fakehd\n"
  403. " Change the ubd device name to \"hd\".\n\n"
  404. );
  405. static void do_ubd_request(request_queue_t * q);
  406. /* Only changed by ubd_init, which is an initcall. */
  407. int thread_fd = -1;
  408. /* Changed by ubd_handler, which is serialized because interrupts only
  409. * happen on CPU 0.
  410. */
  411. int intr_count = 0;
  412. /* call ubd_finish if you need to serialize */
  413. static void __ubd_finish(struct request *req, int error)
  414. {
  415. int nsect;
  416. if(error){
  417. end_request(req, 0);
  418. return;
  419. }
  420. nsect = req->current_nr_sectors;
  421. req->sector += nsect;
  422. req->buffer += nsect << 9;
  423. req->errors = 0;
  424. req->nr_sectors -= nsect;
  425. req->current_nr_sectors = 0;
  426. end_request(req, 1);
  427. }
  428. static inline void ubd_finish(struct request *req, int error)
  429. {
  430. spin_lock(&ubd_io_lock);
  431. __ubd_finish(req, error);
  432. spin_unlock(&ubd_io_lock);
  433. }
  434. /* Called without ubd_io_lock held */
  435. static void ubd_handler(void)
  436. {
  437. struct io_thread_req req;
  438. struct request *rq = elv_next_request(ubd_queue);
  439. int n;
  440. do_ubd = NULL;
  441. intr_count++;
  442. n = os_read_file(thread_fd, &req, sizeof(req));
  443. if(n != sizeof(req)){
  444. printk(KERN_ERR "Pid %d - spurious interrupt in ubd_handler, "
  445. "err = %d\n", os_getpid(), -n);
  446. spin_lock(&ubd_io_lock);
  447. end_request(rq, 0);
  448. spin_unlock(&ubd_io_lock);
  449. return;
  450. }
  451. ubd_finish(rq, req.error);
  452. reactivate_fd(thread_fd, UBD_IRQ);
  453. do_ubd_request(ubd_queue);
  454. }
  455. static irqreturn_t ubd_intr(int irq, void *dev, struct pt_regs *unused)
  456. {
  457. ubd_handler();
  458. return(IRQ_HANDLED);
  459. }
  460. /* Only changed by ubd_init, which is an initcall. */
  461. static int io_pid = -1;
  462. void kill_io_thread(void)
  463. {
  464. if(io_pid != -1)
  465. os_kill_process(io_pid, 1);
  466. }
  467. __uml_exitcall(kill_io_thread);
  468. static int ubd_file_size(struct ubd *dev, __u64 *size_out)
  469. {
  470. char *file;
  471. file = dev->cow.file ? dev->cow.file : dev->file;
  472. return(os_file_size(file, size_out));
  473. }
  474. static void ubd_close(struct ubd *dev)
  475. {
  476. os_close_file(dev->fd);
  477. if(dev->cow.file == NULL)
  478. return;
  479. os_close_file(dev->cow.fd);
  480. vfree(dev->cow.bitmap);
  481. dev->cow.bitmap = NULL;
  482. }
  483. static int ubd_open_dev(struct ubd *dev)
  484. {
  485. struct openflags flags;
  486. char **back_ptr;
  487. int err, create_cow, *create_ptr;
  488. dev->openflags = dev->boot_openflags;
  489. create_cow = 0;
  490. create_ptr = (dev->cow.file != NULL) ? &create_cow : NULL;
  491. back_ptr = dev->no_cow ? NULL : &dev->cow.file;
  492. dev->fd = open_ubd_file(dev->file, &dev->openflags, dev->shared,
  493. back_ptr, &dev->cow.bitmap_offset,
  494. &dev->cow.bitmap_len, &dev->cow.data_offset,
  495. create_ptr);
  496. if((dev->fd == -ENOENT) && create_cow){
  497. dev->fd = create_cow_file(dev->file, dev->cow.file,
  498. dev->openflags, 1 << 9, PAGE_SIZE,
  499. &dev->cow.bitmap_offset,
  500. &dev->cow.bitmap_len,
  501. &dev->cow.data_offset);
  502. if(dev->fd >= 0){
  503. printk(KERN_INFO "Creating \"%s\" as COW file for "
  504. "\"%s\"\n", dev->file, dev->cow.file);
  505. }
  506. }
  507. if(dev->fd < 0){
  508. printk("Failed to open '%s', errno = %d\n", dev->file,
  509. -dev->fd);
  510. return(dev->fd);
  511. }
  512. if(dev->cow.file != NULL){
  513. err = -ENOMEM;
  514. dev->cow.bitmap = (void *) vmalloc(dev->cow.bitmap_len);
  515. if(dev->cow.bitmap == NULL){
  516. printk(KERN_ERR "Failed to vmalloc COW bitmap\n");
  517. goto error;
  518. }
  519. flush_tlb_kernel_vm();
  520. err = read_cow_bitmap(dev->fd, dev->cow.bitmap,
  521. dev->cow.bitmap_offset,
  522. dev->cow.bitmap_len);
  523. if(err < 0)
  524. goto error;
  525. flags = dev->openflags;
  526. flags.w = 0;
  527. err = open_ubd_file(dev->cow.file, &flags, dev->shared, NULL,
  528. NULL, NULL, NULL, NULL);
  529. if(err < 0) goto error;
  530. dev->cow.fd = err;
  531. }
  532. return(0);
  533. error:
  534. os_close_file(dev->fd);
  535. return(err);
  536. }
  537. static int ubd_new_disk(int major, u64 size, int unit,
  538. struct gendisk **disk_out)
  539. {
  540. struct gendisk *disk;
  541. int err;
  542. disk = alloc_disk(1 << UBD_SHIFT);
  543. if(disk == NULL)
  544. return(-ENOMEM);
  545. disk->major = major;
  546. disk->first_minor = unit << UBD_SHIFT;
  547. disk->fops = &ubd_blops;
  548. set_capacity(disk, size / 512);
  549. if(major == MAJOR_NR){
  550. sprintf(disk->disk_name, "ubd%c", 'a' + unit);
  551. sprintf(disk->devfs_name, "ubd/disc%d", unit);
  552. }
  553. else {
  554. sprintf(disk->disk_name, "ubd_fake%d", unit);
  555. sprintf(disk->devfs_name, "ubd_fake/disc%d", unit);
  556. }
  557. /* sysfs register (not for ide fake devices) */
  558. if (major == MAJOR_NR) {
  559. ubd_dev[unit].pdev.id = unit;
  560. ubd_dev[unit].pdev.name = DRIVER_NAME;
  561. platform_device_register(&ubd_dev[unit].pdev);
  562. disk->driverfs_dev = &ubd_dev[unit].pdev.dev;
  563. }
  564. disk->private_data = &ubd_dev[unit];
  565. disk->queue = ubd_queue;
  566. add_disk(disk);
  567. *disk_out = disk;
  568. return 0;
  569. }
  570. #define ROUND_BLOCK(n) ((n + ((1 << 9) - 1)) & (-1 << 9))
  571. static int ubd_add(int n)
  572. {
  573. struct ubd *dev = &ubd_dev[n];
  574. int err;
  575. err = -ENODEV;
  576. if(dev->file == NULL)
  577. goto out;
  578. if (ubd_open_dev(dev))
  579. goto out;
  580. err = ubd_file_size(dev, &dev->size);
  581. if(err < 0)
  582. goto out_close;
  583. dev->size = ROUND_BLOCK(dev->size);
  584. err = ubd_new_disk(MAJOR_NR, dev->size, n, &ubd_gendisk[n]);
  585. if(err)
  586. goto out_close;
  587. if(fake_major != MAJOR_NR)
  588. ubd_new_disk(fake_major, dev->size, n,
  589. &fake_gendisk[n]);
  590. /* perhaps this should also be under the "if (fake_major)" above */
  591. /* using the fake_disk->disk_name and also the fakehd_set name */
  592. if (fake_ide)
  593. make_ide_entries(ubd_gendisk[n]->disk_name);
  594. err = 0;
  595. out_close:
  596. ubd_close(dev);
  597. out:
  598. return err;
  599. }
  600. static int ubd_config(char *str)
  601. {
  602. int n, err;
  603. str = kstrdup(str, GFP_KERNEL);
  604. if(str == NULL){
  605. printk(KERN_ERR "ubd_config failed to strdup string\n");
  606. return(1);
  607. }
  608. err = ubd_setup_common(str, &n);
  609. if(err){
  610. kfree(str);
  611. return(-1);
  612. }
  613. if(n == -1) return(0);
  614. spin_lock(&ubd_lock);
  615. err = ubd_add(n);
  616. if(err)
  617. ubd_dev[n].file = NULL;
  618. spin_unlock(&ubd_lock);
  619. return(err);
  620. }
  621. static int ubd_get_config(char *name, char *str, int size, char **error_out)
  622. {
  623. struct ubd *dev;
  624. int n, len = 0;
  625. n = parse_unit(&name);
  626. if((n >= MAX_DEV) || (n < 0)){
  627. *error_out = "ubd_get_config : device number out of range";
  628. return(-1);
  629. }
  630. dev = &ubd_dev[n];
  631. spin_lock(&ubd_lock);
  632. if(dev->file == NULL){
  633. CONFIG_CHUNK(str, size, len, "", 1);
  634. goto out;
  635. }
  636. CONFIG_CHUNK(str, size, len, dev->file, 0);
  637. if(dev->cow.file != NULL){
  638. CONFIG_CHUNK(str, size, len, ",", 0);
  639. CONFIG_CHUNK(str, size, len, dev->cow.file, 1);
  640. }
  641. else CONFIG_CHUNK(str, size, len, "", 1);
  642. out:
  643. spin_unlock(&ubd_lock);
  644. return(len);
  645. }
  646. static int ubd_id(char **str, int *start_out, int *end_out)
  647. {
  648. int n;
  649. n = parse_unit(str);
  650. *start_out = 0;
  651. *end_out = MAX_DEV - 1;
  652. return n;
  653. }
  654. static int ubd_remove(int n)
  655. {
  656. struct ubd *dev;
  657. int err = -ENODEV;
  658. spin_lock(&ubd_lock);
  659. if(ubd_gendisk[n] == NULL)
  660. goto out;
  661. dev = &ubd_dev[n];
  662. if(dev->file == NULL)
  663. goto out;
  664. /* you cannot remove a open disk */
  665. err = -EBUSY;
  666. if(dev->count > 0)
  667. goto out;
  668. del_gendisk(ubd_gendisk[n]);
  669. put_disk(ubd_gendisk[n]);
  670. ubd_gendisk[n] = NULL;
  671. if(fake_gendisk[n] != NULL){
  672. del_gendisk(fake_gendisk[n]);
  673. put_disk(fake_gendisk[n]);
  674. fake_gendisk[n] = NULL;
  675. }
  676. platform_device_unregister(&dev->pdev);
  677. *dev = ((struct ubd) DEFAULT_UBD);
  678. err = 0;
  679. out:
  680. spin_unlock(&ubd_lock);
  681. return err;
  682. }
  683. static struct mc_device ubd_mc = {
  684. .name = "ubd",
  685. .config = ubd_config,
  686. .get_config = ubd_get_config,
  687. .id = ubd_id,
  688. .remove = ubd_remove,
  689. };
  690. static int ubd_mc_init(void)
  691. {
  692. mconsole_register_dev(&ubd_mc);
  693. return 0;
  694. }
  695. __initcall(ubd_mc_init);
  696. static struct platform_driver ubd_driver = {
  697. .driver = {
  698. .name = DRIVER_NAME,
  699. },
  700. };
  701. int ubd_init(void)
  702. {
  703. int i;
  704. if (register_blkdev(MAJOR_NR, "ubd"))
  705. return -1;
  706. ubd_queue = blk_init_queue(do_ubd_request, &ubd_io_lock);
  707. if (!ubd_queue) {
  708. unregister_blkdev(MAJOR_NR, "ubd");
  709. return -1;
  710. }
  711. if (fake_major != MAJOR_NR) {
  712. char name[sizeof("ubd_nnn\0")];
  713. snprintf(name, sizeof(name), "ubd_%d", fake_major);
  714. if (register_blkdev(fake_major, "ubd"))
  715. return -1;
  716. }
  717. platform_driver_register(&ubd_driver);
  718. for (i = 0; i < MAX_DEV; i++)
  719. ubd_add(i);
  720. return 0;
  721. }
  722. late_initcall(ubd_init);
  723. int ubd_driver_init(void){
  724. unsigned long stack;
  725. int err;
  726. /* Set by CONFIG_BLK_DEV_UBD_SYNC or ubd=sync.*/
  727. if(global_openflags.s){
  728. printk(KERN_INFO "ubd: Synchronous mode\n");
  729. /* Letting ubd=sync be like using ubd#s= instead of ubd#= is
  730. * enough. So use anyway the io thread. */
  731. }
  732. stack = alloc_stack(0, 0);
  733. io_pid = start_io_thread(stack + PAGE_SIZE - sizeof(void *),
  734. &thread_fd);
  735. if(io_pid < 0){
  736. printk(KERN_ERR
  737. "ubd : Failed to start I/O thread (errno = %d) - "
  738. "falling back to synchronous I/O\n", -io_pid);
  739. io_pid = -1;
  740. return(0);
  741. }
  742. err = um_request_irq(UBD_IRQ, thread_fd, IRQ_READ, ubd_intr,
  743. SA_INTERRUPT, "ubd", ubd_dev);
  744. if(err != 0)
  745. printk(KERN_ERR "um_request_irq failed - errno = %d\n", -err);
  746. return 0;
  747. }
  748. device_initcall(ubd_driver_init);
  749. static int ubd_open(struct inode *inode, struct file *filp)
  750. {
  751. struct gendisk *disk = inode->i_bdev->bd_disk;
  752. struct ubd *dev = disk->private_data;
  753. int err = 0;
  754. if(dev->count == 0){
  755. err = ubd_open_dev(dev);
  756. if(err){
  757. printk(KERN_ERR "%s: Can't open \"%s\": errno = %d\n",
  758. disk->disk_name, dev->file, -err);
  759. goto out;
  760. }
  761. }
  762. dev->count++;
  763. set_disk_ro(disk, !dev->openflags.w);
  764. /* This should no more be needed. And it didn't work anyway to exclude
  765. * read-write remounting of filesystems.*/
  766. /*if((filp->f_mode & FMODE_WRITE) && !dev->openflags.w){
  767. if(--dev->count == 0) ubd_close(dev);
  768. err = -EROFS;
  769. }*/
  770. out:
  771. return(err);
  772. }
  773. static int ubd_release(struct inode * inode, struct file * file)
  774. {
  775. struct gendisk *disk = inode->i_bdev->bd_disk;
  776. struct ubd *dev = disk->private_data;
  777. if(--dev->count == 0)
  778. ubd_close(dev);
  779. return(0);
  780. }
  781. static void cowify_bitmap(__u64 io_offset, int length, unsigned long *cow_mask,
  782. __u64 *cow_offset, unsigned long *bitmap,
  783. __u64 bitmap_offset, unsigned long *bitmap_words,
  784. __u64 bitmap_len)
  785. {
  786. __u64 sector = io_offset >> 9;
  787. int i, update_bitmap = 0;
  788. for(i = 0; i < length >> 9; i++){
  789. if(cow_mask != NULL)
  790. ubd_set_bit(i, (unsigned char *) cow_mask);
  791. if(ubd_test_bit(sector + i, (unsigned char *) bitmap))
  792. continue;
  793. update_bitmap = 1;
  794. ubd_set_bit(sector + i, (unsigned char *) bitmap);
  795. }
  796. if(!update_bitmap)
  797. return;
  798. *cow_offset = sector / (sizeof(unsigned long) * 8);
  799. /* This takes care of the case where we're exactly at the end of the
  800. * device, and *cow_offset + 1 is off the end. So, just back it up
  801. * by one word. Thanks to Lynn Kerby for the fix and James McMechan
  802. * for the original diagnosis.
  803. */
  804. if(*cow_offset == ((bitmap_len + sizeof(unsigned long) - 1) /
  805. sizeof(unsigned long) - 1))
  806. (*cow_offset)--;
  807. bitmap_words[0] = bitmap[*cow_offset];
  808. bitmap_words[1] = bitmap[*cow_offset + 1];
  809. *cow_offset *= sizeof(unsigned long);
  810. *cow_offset += bitmap_offset;
  811. }
  812. static void cowify_req(struct io_thread_req *req, unsigned long *bitmap,
  813. __u64 bitmap_offset, __u64 bitmap_len)
  814. {
  815. __u64 sector = req->offset >> 9;
  816. int i;
  817. if(req->length > (sizeof(req->sector_mask) * 8) << 9)
  818. panic("Operation too long");
  819. if(req->op == UBD_READ) {
  820. for(i = 0; i < req->length >> 9; i++){
  821. if(ubd_test_bit(sector + i, (unsigned char *) bitmap))
  822. ubd_set_bit(i, (unsigned char *)
  823. &req->sector_mask);
  824. }
  825. }
  826. else cowify_bitmap(req->offset, req->length, &req->sector_mask,
  827. &req->cow_offset, bitmap, bitmap_offset,
  828. req->bitmap_words, bitmap_len);
  829. }
  830. /* Called with ubd_io_lock held */
  831. static int prepare_request(struct request *req, struct io_thread_req *io_req)
  832. {
  833. struct gendisk *disk = req->rq_disk;
  834. struct ubd *dev = disk->private_data;
  835. __u64 offset;
  836. int len;
  837. if(req->rq_status == RQ_INACTIVE) return(1);
  838. /* This should be impossible now */
  839. if((rq_data_dir(req) == WRITE) && !dev->openflags.w){
  840. printk("Write attempted on readonly ubd device %s\n",
  841. disk->disk_name);
  842. end_request(req, 0);
  843. return(1);
  844. }
  845. offset = ((__u64) req->sector) << 9;
  846. len = req->current_nr_sectors << 9;
  847. io_req->fds[0] = (dev->cow.file != NULL) ? dev->cow.fd : dev->fd;
  848. io_req->fds[1] = dev->fd;
  849. io_req->cow_offset = -1;
  850. io_req->offset = offset;
  851. io_req->length = len;
  852. io_req->error = 0;
  853. io_req->sector_mask = 0;
  854. io_req->op = (rq_data_dir(req) == READ) ? UBD_READ : UBD_WRITE;
  855. io_req->offsets[0] = 0;
  856. io_req->offsets[1] = dev->cow.data_offset;
  857. io_req->buffer = req->buffer;
  858. io_req->sectorsize = 1 << 9;
  859. if(dev->cow.file != NULL)
  860. cowify_req(io_req, dev->cow.bitmap, dev->cow.bitmap_offset,
  861. dev->cow.bitmap_len);
  862. return(0);
  863. }
  864. /* Called with ubd_io_lock held */
  865. static void do_ubd_request(request_queue_t *q)
  866. {
  867. struct io_thread_req io_req;
  868. struct request *req;
  869. int err, n;
  870. if(thread_fd == -1){
  871. while((req = elv_next_request(q)) != NULL){
  872. err = prepare_request(req, &io_req);
  873. if(!err){
  874. do_io(&io_req);
  875. __ubd_finish(req, io_req.error);
  876. }
  877. }
  878. }
  879. else {
  880. if(do_ubd || (req = elv_next_request(q)) == NULL)
  881. return;
  882. err = prepare_request(req, &io_req);
  883. if(!err){
  884. do_ubd = ubd_handler;
  885. n = os_write_file(thread_fd, (char *) &io_req,
  886. sizeof(io_req));
  887. if(n != sizeof(io_req))
  888. printk("write to io thread failed, "
  889. "errno = %d\n", -n);
  890. }
  891. }
  892. }
  893. static int ubd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
  894. {
  895. struct ubd *dev = bdev->bd_disk->private_data;
  896. geo->heads = 128;
  897. geo->sectors = 32;
  898. geo->cylinders = dev->size / (128 * 32 * 512);
  899. return 0;
  900. }
  901. static int ubd_ioctl(struct inode * inode, struct file * file,
  902. unsigned int cmd, unsigned long arg)
  903. {
  904. struct ubd *dev = inode->i_bdev->bd_disk->private_data;
  905. struct hd_driveid ubd_id = {
  906. .cyls = 0,
  907. .heads = 128,
  908. .sectors = 32,
  909. };
  910. switch (cmd) {
  911. struct cdrom_volctrl volume;
  912. case HDIO_GET_IDENTITY:
  913. ubd_id.cyls = dev->size / (128 * 32 * 512);
  914. if(copy_to_user((char __user *) arg, (char *) &ubd_id,
  915. sizeof(ubd_id)))
  916. return(-EFAULT);
  917. return(0);
  918. case CDROMVOLREAD:
  919. if(copy_from_user(&volume, (char __user *) arg, sizeof(volume)))
  920. return(-EFAULT);
  921. volume.channel0 = 255;
  922. volume.channel1 = 255;
  923. volume.channel2 = 255;
  924. volume.channel3 = 255;
  925. if(copy_to_user((char __user *) arg, &volume, sizeof(volume)))
  926. return(-EFAULT);
  927. return(0);
  928. }
  929. return(-EINVAL);
  930. }
  931. static int path_requires_switch(char *from_cmdline, char *from_cow, char *cow)
  932. {
  933. struct uml_stat buf1, buf2;
  934. int err;
  935. if(from_cmdline == NULL)
  936. return 0;
  937. if(!strcmp(from_cmdline, from_cow))
  938. return 0;
  939. err = os_stat_file(from_cmdline, &buf1);
  940. if(err < 0){
  941. printk("Couldn't stat '%s', err = %d\n", from_cmdline, -err);
  942. return 0;
  943. }
  944. err = os_stat_file(from_cow, &buf2);
  945. if(err < 0){
  946. printk("Couldn't stat '%s', err = %d\n", from_cow, -err);
  947. return 1;
  948. }
  949. if((buf1.ust_dev == buf2.ust_dev) && (buf1.ust_ino == buf2.ust_ino))
  950. return 0;
  951. printk("Backing file mismatch - \"%s\" requested,\n"
  952. "\"%s\" specified in COW header of \"%s\"\n",
  953. from_cmdline, from_cow, cow);
  954. return 1;
  955. }
  956. static int backing_file_mismatch(char *file, __u64 size, time_t mtime)
  957. {
  958. unsigned long modtime;
  959. unsigned long long actual;
  960. int err;
  961. err = os_file_modtime(file, &modtime);
  962. if(err < 0){
  963. printk("Failed to get modification time of backing file "
  964. "\"%s\", err = %d\n", file, -err);
  965. return(err);
  966. }
  967. err = os_file_size(file, &actual);
  968. if(err < 0){
  969. printk("Failed to get size of backing file \"%s\", "
  970. "err = %d\n", file, -err);
  971. return(err);
  972. }
  973. if(actual != size){
  974. /*__u64 can be a long on AMD64 and with %lu GCC complains; so
  975. * the typecast.*/
  976. printk("Size mismatch (%llu vs %llu) of COW header vs backing "
  977. "file\n", (unsigned long long) size, actual);
  978. return(-EINVAL);
  979. }
  980. if(modtime != mtime){
  981. printk("mtime mismatch (%ld vs %ld) of COW header vs backing "
  982. "file\n", mtime, modtime);
  983. return(-EINVAL);
  984. }
  985. return(0);
  986. }
  987. int read_cow_bitmap(int fd, void *buf, int offset, int len)
  988. {
  989. int err;
  990. err = os_seek_file(fd, offset);
  991. if(err < 0)
  992. return(err);
  993. err = os_read_file(fd, buf, len);
  994. if(err < 0)
  995. return(err);
  996. return(0);
  997. }
  998. int open_ubd_file(char *file, struct openflags *openflags, int shared,
  999. char **backing_file_out, int *bitmap_offset_out,
  1000. unsigned long *bitmap_len_out, int *data_offset_out,
  1001. int *create_cow_out)
  1002. {
  1003. time_t mtime;
  1004. unsigned long long size;
  1005. __u32 version, align;
  1006. char *backing_file;
  1007. int fd, err, sectorsize, asked_switch, mode = 0644;
  1008. fd = os_open_file(file, *openflags, mode);
  1009. if (fd < 0) {
  1010. if ((fd == -ENOENT) && (create_cow_out != NULL))
  1011. *create_cow_out = 1;
  1012. if (!openflags->w ||
  1013. ((fd != -EROFS) && (fd != -EACCES)))
  1014. return fd;
  1015. openflags->w = 0;
  1016. fd = os_open_file(file, *openflags, mode);
  1017. if (fd < 0)
  1018. return fd;
  1019. }
  1020. if(shared)
  1021. printk("Not locking \"%s\" on the host\n", file);
  1022. else {
  1023. err = os_lock_file(fd, openflags->w);
  1024. if(err < 0){
  1025. printk("Failed to lock '%s', err = %d\n", file, -err);
  1026. goto out_close;
  1027. }
  1028. }
  1029. /* Succesful return case! */
  1030. if(backing_file_out == NULL)
  1031. return(fd);
  1032. err = read_cow_header(file_reader, &fd, &version, &backing_file, &mtime,
  1033. &size, &sectorsize, &align, bitmap_offset_out);
  1034. if(err && (*backing_file_out != NULL)){
  1035. printk("Failed to read COW header from COW file \"%s\", "
  1036. "errno = %d\n", file, -err);
  1037. goto out_close;
  1038. }
  1039. if(err)
  1040. return(fd);
  1041. asked_switch = path_requires_switch(*backing_file_out, backing_file, file);
  1042. /* Allow switching only if no mismatch. */
  1043. if (asked_switch && !backing_file_mismatch(*backing_file_out, size, mtime)) {
  1044. printk("Switching backing file to '%s'\n", *backing_file_out);
  1045. err = write_cow_header(file, fd, *backing_file_out,
  1046. sectorsize, align, &size);
  1047. if (err) {
  1048. printk("Switch failed, errno = %d\n", -err);
  1049. goto out_close;
  1050. }
  1051. } else {
  1052. *backing_file_out = backing_file;
  1053. err = backing_file_mismatch(*backing_file_out, size, mtime);
  1054. if (err)
  1055. goto out_close;
  1056. }
  1057. cow_sizes(version, size, sectorsize, align, *bitmap_offset_out,
  1058. bitmap_len_out, data_offset_out);
  1059. return fd;
  1060. out_close:
  1061. os_close_file(fd);
  1062. return err;
  1063. }
  1064. int create_cow_file(char *cow_file, char *backing_file, struct openflags flags,
  1065. int sectorsize, int alignment, int *bitmap_offset_out,
  1066. unsigned long *bitmap_len_out, int *data_offset_out)
  1067. {
  1068. int err, fd;
  1069. flags.c = 1;
  1070. fd = open_ubd_file(cow_file, &flags, 0, NULL, NULL, NULL, NULL, NULL);
  1071. if(fd < 0){
  1072. err = fd;
  1073. printk("Open of COW file '%s' failed, errno = %d\n", cow_file,
  1074. -err);
  1075. goto out;
  1076. }
  1077. err = init_cow_file(fd, cow_file, backing_file, sectorsize, alignment,
  1078. bitmap_offset_out, bitmap_len_out,
  1079. data_offset_out);
  1080. if(!err)
  1081. return(fd);
  1082. os_close_file(fd);
  1083. out:
  1084. return(err);
  1085. }
  1086. static int update_bitmap(struct io_thread_req *req)
  1087. {
  1088. int n;
  1089. if(req->cow_offset == -1)
  1090. return(0);
  1091. n = os_seek_file(req->fds[1], req->cow_offset);
  1092. if(n < 0){
  1093. printk("do_io - bitmap lseek failed : err = %d\n", -n);
  1094. return(1);
  1095. }
  1096. n = os_write_file(req->fds[1], &req->bitmap_words,
  1097. sizeof(req->bitmap_words));
  1098. if(n != sizeof(req->bitmap_words)){
  1099. printk("do_io - bitmap update failed, err = %d fd = %d\n", -n,
  1100. req->fds[1]);
  1101. return(1);
  1102. }
  1103. return(0);
  1104. }
  1105. void do_io(struct io_thread_req *req)
  1106. {
  1107. char *buf;
  1108. unsigned long len;
  1109. int n, nsectors, start, end, bit;
  1110. int err;
  1111. __u64 off;
  1112. nsectors = req->length / req->sectorsize;
  1113. start = 0;
  1114. do {
  1115. bit = ubd_test_bit(start, (unsigned char *) &req->sector_mask);
  1116. end = start;
  1117. while((end < nsectors) &&
  1118. (ubd_test_bit(end, (unsigned char *)
  1119. &req->sector_mask) == bit))
  1120. end++;
  1121. off = req->offset + req->offsets[bit] +
  1122. start * req->sectorsize;
  1123. len = (end - start) * req->sectorsize;
  1124. buf = &req->buffer[start * req->sectorsize];
  1125. err = os_seek_file(req->fds[bit], off);
  1126. if(err < 0){
  1127. printk("do_io - lseek failed : err = %d\n", -err);
  1128. req->error = 1;
  1129. return;
  1130. }
  1131. if(req->op == UBD_READ){
  1132. n = 0;
  1133. do {
  1134. buf = &buf[n];
  1135. len -= n;
  1136. n = os_read_file(req->fds[bit], buf, len);
  1137. if (n < 0) {
  1138. printk("do_io - read failed, err = %d "
  1139. "fd = %d\n", -n, req->fds[bit]);
  1140. req->error = 1;
  1141. return;
  1142. }
  1143. } while((n < len) && (n != 0));
  1144. if (n < len) memset(&buf[n], 0, len - n);
  1145. } else {
  1146. n = os_write_file(req->fds[bit], buf, len);
  1147. if(n != len){
  1148. printk("do_io - write failed err = %d "
  1149. "fd = %d\n", -n, req->fds[bit]);
  1150. req->error = 1;
  1151. return;
  1152. }
  1153. }
  1154. start = end;
  1155. } while(start < nsectors);
  1156. req->error = update_bitmap(req);
  1157. }
  1158. /* Changed in start_io_thread, which is serialized by being called only
  1159. * from ubd_init, which is an initcall.
  1160. */
  1161. int kernel_fd = -1;
  1162. /* Only changed by the io thread */
  1163. int io_count = 0;
  1164. int io_thread(void *arg)
  1165. {
  1166. struct io_thread_req req;
  1167. int n;
  1168. ignore_sigwinch_sig();
  1169. while(1){
  1170. n = os_read_file(kernel_fd, &req, sizeof(req));
  1171. if(n != sizeof(req)){
  1172. if(n < 0)
  1173. printk("io_thread - read failed, fd = %d, "
  1174. "err = %d\n", kernel_fd, -n);
  1175. else {
  1176. printk("io_thread - short read, fd = %d, "
  1177. "length = %d\n", kernel_fd, n);
  1178. }
  1179. continue;
  1180. }
  1181. io_count++;
  1182. do_io(&req);
  1183. n = os_write_file(kernel_fd, &req, sizeof(req));
  1184. if(n != sizeof(req))
  1185. printk("io_thread - write failed, fd = %d, err = %d\n",
  1186. kernel_fd, -n);
  1187. }
  1188. return 0;
  1189. }