ubd_kern.c 32 KB

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