ubd_kern.c 32 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/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 "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,
  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. #define MAX_DEV (8)
  106. static struct block_device_operations ubd_blops = {
  107. .owner = THIS_MODULE,
  108. .open = ubd_open,
  109. .release = ubd_release,
  110. .ioctl = ubd_ioctl,
  111. };
  112. /* Protected by the queue_lock */
  113. static request_queue_t *ubd_queue;
  114. /* Protected by ubd_lock */
  115. static int fake_major = MAJOR_NR;
  116. static struct gendisk *ubd_gendisk[MAX_DEV];
  117. static struct gendisk *fake_gendisk[MAX_DEV];
  118. #ifdef CONFIG_BLK_DEV_UBD_SYNC
  119. #define OPEN_FLAGS ((struct openflags) { .r = 1, .w = 1, .s = 1, .c = 0, \
  120. .cl = 1 })
  121. #else
  122. #define OPEN_FLAGS ((struct openflags) { .r = 1, .w = 1, .s = 0, .c = 0, \
  123. .cl = 1 })
  124. #endif
  125. /* Not protected - changed only in ubd_setup_common and then only to
  126. * to enable O_SYNC.
  127. */
  128. static struct openflags global_openflags = OPEN_FLAGS;
  129. struct cow {
  130. /* This is the backing file, actually */
  131. char *file;
  132. int fd;
  133. unsigned long *bitmap;
  134. unsigned long bitmap_len;
  135. int bitmap_offset;
  136. int data_offset;
  137. };
  138. struct ubd {
  139. char *file;
  140. int count;
  141. int fd;
  142. __u64 size;
  143. struct openflags boot_openflags;
  144. struct openflags openflags;
  145. int no_cow;
  146. struct cow cow;
  147. struct platform_device pdev;
  148. };
  149. #define DEFAULT_COW { \
  150. .file = NULL, \
  151. .fd = -1, \
  152. .bitmap = NULL, \
  153. .bitmap_offset = 0, \
  154. .data_offset = 0, \
  155. }
  156. #define DEFAULT_UBD { \
  157. .file = NULL, \
  158. .count = 0, \
  159. .fd = -1, \
  160. .size = -1, \
  161. .boot_openflags = OPEN_FLAGS, \
  162. .openflags = OPEN_FLAGS, \
  163. .no_cow = 0, \
  164. .cow = DEFAULT_COW, \
  165. }
  166. struct ubd ubd_dev[MAX_DEV] = { [ 0 ... MAX_DEV - 1 ] = DEFAULT_UBD };
  167. static int ubd0_init(void)
  168. {
  169. struct ubd *dev = &ubd_dev[0];
  170. if(dev->file == NULL)
  171. dev->file = "root_fs";
  172. return(0);
  173. }
  174. __initcall(ubd0_init);
  175. /* Only changed by fake_ide_setup which is a setup */
  176. static int fake_ide = 0;
  177. static struct proc_dir_entry *proc_ide_root = NULL;
  178. static struct proc_dir_entry *proc_ide = NULL;
  179. static void make_proc_ide(void)
  180. {
  181. proc_ide_root = proc_mkdir("ide", NULL);
  182. proc_ide = proc_mkdir("ide0", proc_ide_root);
  183. }
  184. static int proc_ide_read_media(char *page, char **start, off_t off, int count,
  185. int *eof, void *data)
  186. {
  187. int len;
  188. strcpy(page, "disk\n");
  189. len = strlen("disk\n");
  190. len -= off;
  191. if (len < count){
  192. *eof = 1;
  193. if (len <= 0) return 0;
  194. }
  195. else len = count;
  196. *start = page + off;
  197. return len;
  198. }
  199. static void make_ide_entries(char *dev_name)
  200. {
  201. struct proc_dir_entry *dir, *ent;
  202. char name[64];
  203. if(proc_ide_root == NULL) make_proc_ide();
  204. dir = proc_mkdir(dev_name, proc_ide);
  205. if(!dir) return;
  206. ent = create_proc_entry("media", S_IFREG|S_IRUGO, dir);
  207. if(!ent) return;
  208. ent->nlink = 1;
  209. ent->data = NULL;
  210. ent->read_proc = proc_ide_read_media;
  211. ent->write_proc = NULL;
  212. sprintf(name,"ide0/%s", dev_name);
  213. proc_symlink(dev_name, proc_ide_root, name);
  214. }
  215. static int fake_ide_setup(char *str)
  216. {
  217. fake_ide = 1;
  218. return(1);
  219. }
  220. __setup("fake_ide", fake_ide_setup);
  221. __uml_help(fake_ide_setup,
  222. "fake_ide\n"
  223. " Create ide0 entries that map onto ubd devices.\n\n"
  224. );
  225. static int parse_unit(char **ptr)
  226. {
  227. char *str = *ptr, *end;
  228. int n = -1;
  229. if(isdigit(*str)) {
  230. n = simple_strtoul(str, &end, 0);
  231. if(end == str)
  232. return(-1);
  233. *ptr = end;
  234. }
  235. else if (('a' <= *str) && (*str <= 'h')) {
  236. n = *str - 'a';
  237. str++;
  238. *ptr = str;
  239. }
  240. return(n);
  241. }
  242. static int ubd_setup_common(char *str, int *index_out)
  243. {
  244. struct ubd *dev;
  245. struct openflags flags = global_openflags;
  246. char *backing_file;
  247. int n, err, i;
  248. if(index_out) *index_out = -1;
  249. n = *str;
  250. if(n == '='){
  251. char *end;
  252. int major;
  253. str++;
  254. if(!strcmp(str, "sync")){
  255. global_openflags = of_sync(global_openflags);
  256. return(0);
  257. }
  258. major = simple_strtoul(str, &end, 0);
  259. if((*end != '\0') || (end == str)){
  260. printk(KERN_ERR
  261. "ubd_setup : didn't parse major number\n");
  262. return(1);
  263. }
  264. err = 1;
  265. spin_lock(&ubd_lock);
  266. if(fake_major != MAJOR_NR){
  267. printk(KERN_ERR "Can't assign a fake major twice\n");
  268. goto out1;
  269. }
  270. fake_major = major;
  271. printk(KERN_INFO "Setting extra ubd major number to %d\n",
  272. major);
  273. err = 0;
  274. out1:
  275. spin_unlock(&ubd_lock);
  276. return(err);
  277. }
  278. n = parse_unit(&str);
  279. if(n < 0){
  280. printk(KERN_ERR "ubd_setup : couldn't parse unit number "
  281. "'%s'\n", str);
  282. return(1);
  283. }
  284. if(n >= MAX_DEV){
  285. printk(KERN_ERR "ubd_setup : index %d out of range "
  286. "(%d devices, from 0 to %d)\n", n, MAX_DEV, MAX_DEV - 1);
  287. return(1);
  288. }
  289. err = 1;
  290. spin_lock(&ubd_lock);
  291. dev = &ubd_dev[n];
  292. if(dev->file != NULL){
  293. printk(KERN_ERR "ubd_setup : device already configured\n");
  294. goto out;
  295. }
  296. if (index_out)
  297. *index_out = n;
  298. for (i = 0; i < 4; i++) {
  299. switch (*str) {
  300. case 'r':
  301. flags.w = 0;
  302. break;
  303. case 's':
  304. flags.s = 1;
  305. break;
  306. case 'd':
  307. dev->no_cow = 1;
  308. break;
  309. case '=':
  310. str++;
  311. goto break_loop;
  312. default:
  313. printk(KERN_ERR "ubd_setup : Expected '=' or flag letter (r,s or d)\n");
  314. goto out;
  315. }
  316. str++;
  317. }
  318. if (*str == '=')
  319. printk(KERN_ERR "ubd_setup : Too many flags specified\n");
  320. else
  321. printk(KERN_ERR "ubd_setup : Expected '='\n");
  322. goto out;
  323. break_loop:
  324. err = 0;
  325. backing_file = strchr(str, ',');
  326. if (!backing_file) {
  327. backing_file = strchr(str, ':');
  328. }
  329. if(backing_file){
  330. if(dev->no_cow)
  331. printk(KERN_ERR "Can't specify both 'd' and a "
  332. "cow file\n");
  333. else {
  334. *backing_file = '\0';
  335. backing_file++;
  336. }
  337. }
  338. dev->file = str;
  339. dev->cow.file = backing_file;
  340. dev->boot_openflags = flags;
  341. out:
  342. spin_unlock(&ubd_lock);
  343. return(err);
  344. }
  345. static int ubd_setup(char *str)
  346. {
  347. ubd_setup_common(str, NULL);
  348. return(1);
  349. }
  350. __setup("ubd", ubd_setup);
  351. __uml_help(ubd_setup,
  352. "ubd<n><flags>=<filename>[(:|,)<filename2>]\n"
  353. " This is used to associate a device with a file in the underlying\n"
  354. " filesystem. When specifying two filenames, the first one is the\n"
  355. " COW name and the second is the backing file name. As separator you can\n"
  356. " use either a ':' or a ',': the first one allows writing things like;\n"
  357. " ubd0=~/Uml/root_cow:~/Uml/root_backing_file\n"
  358. " while with a ',' the shell would not expand the 2nd '~'.\n"
  359. " When using only one filename, UML will detect whether to thread it like\n"
  360. " a COW file or a backing file. To override this detection, add the 'd'\n"
  361. " flag:\n"
  362. " ubd0d=BackingFile\n"
  363. " Usually, there is a filesystem in the file, but \n"
  364. " that's not required. Swap devices containing swap files can be\n"
  365. " specified like this. Also, a file which doesn't contain a\n"
  366. " filesystem can have its contents read in the virtual \n"
  367. " machine by running 'dd' on the device. <n> must be in the range\n"
  368. " 0 to 7. Appending an 'r' to the number will cause that device\n"
  369. " to be mounted read-only. For example ubd1r=./ext_fs. Appending\n"
  370. " an 's' will cause data to be written to disk on the host immediately.\n\n"
  371. );
  372. static int udb_setup(char *str)
  373. {
  374. printk("udb%s specified on command line is almost certainly a ubd -> "
  375. "udb TYPO\n", str);
  376. return(1);
  377. }
  378. __setup("udb", udb_setup);
  379. __uml_help(udb_setup,
  380. "udb\n"
  381. " This option is here solely to catch ubd -> udb typos, which can be\n"
  382. " to impossible to catch visually unless you specifically look for\n"
  383. " them. The only result of any option starting with 'udb' is an error\n"
  384. " in the boot output.\n\n"
  385. );
  386. static int fakehd_set = 0;
  387. static int fakehd(char *str)
  388. {
  389. printk(KERN_INFO "fakehd : Changing ubd name to \"hd\".\n");
  390. fakehd_set = 1;
  391. return 1;
  392. }
  393. __setup("fakehd", fakehd);
  394. __uml_help(fakehd,
  395. "fakehd\n"
  396. " Change the ubd device name to \"hd\".\n\n"
  397. );
  398. static void do_ubd_request(request_queue_t * q);
  399. /* Only changed by ubd_init, which is an initcall. */
  400. int thread_fd = -1;
  401. /* Changed by ubd_handler, which is serialized because interrupts only
  402. * happen on CPU 0.
  403. */
  404. int intr_count = 0;
  405. /* call ubd_finish if you need to serialize */
  406. static void __ubd_finish(struct request *req, int error)
  407. {
  408. int nsect;
  409. if(error){
  410. end_request(req, 0);
  411. return;
  412. }
  413. nsect = req->current_nr_sectors;
  414. req->sector += nsect;
  415. req->buffer += nsect << 9;
  416. req->errors = 0;
  417. req->nr_sectors -= nsect;
  418. req->current_nr_sectors = 0;
  419. end_request(req, 1);
  420. }
  421. static inline void ubd_finish(struct request *req, int error)
  422. {
  423. spin_lock(&ubd_io_lock);
  424. __ubd_finish(req, error);
  425. spin_unlock(&ubd_io_lock);
  426. }
  427. /* Called without ubd_io_lock held */
  428. static void ubd_handler(void)
  429. {
  430. struct io_thread_req req;
  431. struct request *rq = elv_next_request(ubd_queue);
  432. int n;
  433. do_ubd = NULL;
  434. intr_count++;
  435. n = os_read_file(thread_fd, &req, sizeof(req));
  436. if(n != sizeof(req)){
  437. printk(KERN_ERR "Pid %d - spurious interrupt in ubd_handler, "
  438. "err = %d\n", os_getpid(), -n);
  439. spin_lock(&ubd_io_lock);
  440. end_request(rq, 0);
  441. spin_unlock(&ubd_io_lock);
  442. return;
  443. }
  444. ubd_finish(rq, req.error);
  445. reactivate_fd(thread_fd, UBD_IRQ);
  446. do_ubd_request(ubd_queue);
  447. }
  448. static irqreturn_t ubd_intr(int irq, void *dev, struct pt_regs *unused)
  449. {
  450. ubd_handler();
  451. return(IRQ_HANDLED);
  452. }
  453. /* Only changed by ubd_init, which is an initcall. */
  454. static int io_pid = -1;
  455. void kill_io_thread(void)
  456. {
  457. if(io_pid != -1)
  458. os_kill_process(io_pid, 1);
  459. }
  460. __uml_exitcall(kill_io_thread);
  461. static int ubd_file_size(struct ubd *dev, __u64 *size_out)
  462. {
  463. char *file;
  464. file = dev->cow.file ? dev->cow.file : dev->file;
  465. return(os_file_size(file, size_out));
  466. }
  467. static void ubd_close(struct ubd *dev)
  468. {
  469. os_close_file(dev->fd);
  470. if(dev->cow.file == NULL)
  471. return;
  472. os_close_file(dev->cow.fd);
  473. vfree(dev->cow.bitmap);
  474. dev->cow.bitmap = NULL;
  475. }
  476. static int ubd_open_dev(struct ubd *dev)
  477. {
  478. struct openflags flags;
  479. char **back_ptr;
  480. int err, create_cow, *create_ptr;
  481. dev->openflags = dev->boot_openflags;
  482. create_cow = 0;
  483. create_ptr = (dev->cow.file != NULL) ? &create_cow : NULL;
  484. back_ptr = dev->no_cow ? NULL : &dev->cow.file;
  485. dev->fd = open_ubd_file(dev->file, &dev->openflags, back_ptr,
  486. &dev->cow.bitmap_offset, &dev->cow.bitmap_len,
  487. &dev->cow.data_offset, create_ptr);
  488. if((dev->fd == -ENOENT) && create_cow){
  489. dev->fd = create_cow_file(dev->file, dev->cow.file,
  490. dev->openflags, 1 << 9, PAGE_SIZE,
  491. &dev->cow.bitmap_offset,
  492. &dev->cow.bitmap_len,
  493. &dev->cow.data_offset);
  494. if(dev->fd >= 0){
  495. printk(KERN_INFO "Creating \"%s\" as COW file for "
  496. "\"%s\"\n", dev->file, dev->cow.file);
  497. }
  498. }
  499. if(dev->fd < 0){
  500. printk("Failed to open '%s', errno = %d\n", dev->file,
  501. -dev->fd);
  502. return(dev->fd);
  503. }
  504. if(dev->cow.file != NULL){
  505. err = -ENOMEM;
  506. dev->cow.bitmap = (void *) vmalloc(dev->cow.bitmap_len);
  507. if(dev->cow.bitmap == NULL){
  508. printk(KERN_ERR "Failed to vmalloc COW bitmap\n");
  509. goto error;
  510. }
  511. flush_tlb_kernel_vm();
  512. err = read_cow_bitmap(dev->fd, dev->cow.bitmap,
  513. dev->cow.bitmap_offset,
  514. dev->cow.bitmap_len);
  515. if(err < 0)
  516. goto error;
  517. flags = dev->openflags;
  518. flags.w = 0;
  519. err = open_ubd_file(dev->cow.file, &flags, NULL, NULL, NULL,
  520. NULL, NULL);
  521. if(err < 0) goto error;
  522. dev->cow.fd = err;
  523. }
  524. return(0);
  525. error:
  526. os_close_file(dev->fd);
  527. return(err);
  528. }
  529. static int ubd_new_disk(int major, u64 size, int unit,
  530. struct gendisk **disk_out)
  531. {
  532. struct gendisk *disk;
  533. char from[sizeof("ubd/nnnnn\0")], to[sizeof("discnnnnn/disc\0")];
  534. int err;
  535. disk = alloc_disk(1 << UBD_SHIFT);
  536. if(disk == NULL)
  537. return(-ENOMEM);
  538. disk->major = major;
  539. disk->first_minor = unit << UBD_SHIFT;
  540. disk->fops = &ubd_blops;
  541. set_capacity(disk, size / 512);
  542. if(major == MAJOR_NR){
  543. sprintf(disk->disk_name, "ubd%c", 'a' + unit);
  544. sprintf(disk->devfs_name, "ubd/disc%d", unit);
  545. sprintf(from, "ubd/%d", unit);
  546. sprintf(to, "disc%d/disc", unit);
  547. err = devfs_mk_symlink(from, to);
  548. if(err)
  549. printk("ubd_new_disk failed to make link from %s to "
  550. "%s, error = %d\n", from, to, err);
  551. }
  552. else {
  553. sprintf(disk->disk_name, "ubd_fake%d", unit);
  554. sprintf(disk->devfs_name, "ubd_fake/disc%d", unit);
  555. }
  556. /* sysfs register (not for ide fake devices) */
  557. if (major == MAJOR_NR) {
  558. ubd_dev[unit].pdev.id = unit;
  559. ubd_dev[unit].pdev.name = DRIVER_NAME;
  560. platform_device_register(&ubd_dev[unit].pdev);
  561. disk->driverfs_dev = &ubd_dev[unit].pdev.dev;
  562. }
  563. disk->private_data = &ubd_dev[unit];
  564. disk->queue = ubd_queue;
  565. add_disk(disk);
  566. *disk_out = disk;
  567. return 0;
  568. }
  569. #define ROUND_BLOCK(n) ((n + ((1 << 9) - 1)) & (-1 << 9))
  570. static int ubd_add(int n)
  571. {
  572. struct ubd *dev = &ubd_dev[n];
  573. int err;
  574. err = -ENODEV;
  575. if(dev->file == NULL)
  576. goto out;
  577. if (ubd_open_dev(dev))
  578. goto out;
  579. err = ubd_file_size(dev, &dev->size);
  580. if(err < 0)
  581. goto out_close;
  582. dev->size = ROUND_BLOCK(dev->size);
  583. err = ubd_new_disk(MAJOR_NR, dev->size, n, &ubd_gendisk[n]);
  584. if(err)
  585. goto out_close;
  586. if(fake_major != MAJOR_NR)
  587. ubd_new_disk(fake_major, dev->size, n,
  588. &fake_gendisk[n]);
  589. /* perhaps this should also be under the "if (fake_major)" above */
  590. /* using the fake_disk->disk_name and also the fakehd_set name */
  591. if (fake_ide)
  592. make_ide_entries(ubd_gendisk[n]->disk_name);
  593. err = 0;
  594. out_close:
  595. ubd_close(dev);
  596. out:
  597. return err;
  598. }
  599. static int ubd_config(char *str)
  600. {
  601. int n, err;
  602. str = uml_strdup(str);
  603. if(str == NULL){
  604. printk(KERN_ERR "ubd_config failed to strdup string\n");
  605. return(1);
  606. }
  607. err = ubd_setup_common(str, &n);
  608. if(err){
  609. kfree(str);
  610. return(-1);
  611. }
  612. if(n == -1) return(0);
  613. spin_lock(&ubd_lock);
  614. err = ubd_add(n);
  615. if(err)
  616. ubd_dev[n].file = NULL;
  617. spin_unlock(&ubd_lock);
  618. return(err);
  619. }
  620. static int ubd_get_config(char *name, char *str, int size, char **error_out)
  621. {
  622. struct ubd *dev;
  623. int n, len = 0;
  624. n = parse_unit(&name);
  625. if((n >= MAX_DEV) || (n < 0)){
  626. *error_out = "ubd_get_config : device number out of range";
  627. return(-1);
  628. }
  629. dev = &ubd_dev[n];
  630. spin_lock(&ubd_lock);
  631. if(dev->file == NULL){
  632. CONFIG_CHUNK(str, size, len, "", 1);
  633. goto out;
  634. }
  635. CONFIG_CHUNK(str, size, len, dev->file, 0);
  636. if(dev->cow.file != NULL){
  637. CONFIG_CHUNK(str, size, len, ",", 0);
  638. CONFIG_CHUNK(str, size, len, dev->cow.file, 1);
  639. }
  640. else CONFIG_CHUNK(str, size, len, "", 1);
  641. out:
  642. spin_unlock(&ubd_lock);
  643. return(len);
  644. }
  645. static int ubd_id(char **str, int *start_out, int *end_out)
  646. {
  647. int n;
  648. n = parse_unit(str);
  649. *start_out = 0;
  650. *end_out = MAX_DEV - 1;
  651. return n;
  652. }
  653. static int ubd_remove(int n)
  654. {
  655. struct ubd *dev;
  656. int err = -ENODEV;
  657. spin_lock(&ubd_lock);
  658. if(ubd_gendisk[n] == NULL)
  659. goto out;
  660. dev = &ubd_dev[n];
  661. if(dev->file == NULL)
  662. goto out;
  663. /* you cannot remove a open disk */
  664. err = -EBUSY;
  665. if(dev->count > 0)
  666. goto out;
  667. del_gendisk(ubd_gendisk[n]);
  668. put_disk(ubd_gendisk[n]);
  669. ubd_gendisk[n] = NULL;
  670. if(fake_gendisk[n] != NULL){
  671. del_gendisk(fake_gendisk[n]);
  672. put_disk(fake_gendisk[n]);
  673. fake_gendisk[n] = NULL;
  674. }
  675. platform_device_unregister(&dev->pdev);
  676. *dev = ((struct ubd) DEFAULT_UBD);
  677. err = 0;
  678. out:
  679. spin_unlock(&ubd_lock);
  680. return err;
  681. }
  682. static struct mc_device ubd_mc = {
  683. .name = "ubd",
  684. .config = ubd_config,
  685. .get_config = ubd_get_config,
  686. .id = ubd_id,
  687. .remove = ubd_remove,
  688. };
  689. static int ubd_mc_init(void)
  690. {
  691. mconsole_register_dev(&ubd_mc);
  692. return 0;
  693. }
  694. __initcall(ubd_mc_init);
  695. static struct device_driver ubd_driver = {
  696. .name = DRIVER_NAME,
  697. .bus = &platform_bus_type,
  698. };
  699. int ubd_init(void)
  700. {
  701. int i;
  702. devfs_mk_dir("ubd");
  703. if (register_blkdev(MAJOR_NR, "ubd"))
  704. return -1;
  705. ubd_queue = blk_init_queue(do_ubd_request, &ubd_io_lock);
  706. if (!ubd_queue) {
  707. unregister_blkdev(MAJOR_NR, "ubd");
  708. return -1;
  709. }
  710. if (fake_major != MAJOR_NR) {
  711. char name[sizeof("ubd_nnn\0")];
  712. snprintf(name, sizeof(name), "ubd_%d", fake_major);
  713. devfs_mk_dir(name);
  714. if (register_blkdev(fake_major, "ubd"))
  715. return -1;
  716. }
  717. 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(err);
  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_ioctl(struct inode * inode, struct file * file,
  894. unsigned int cmd, unsigned long arg)
  895. {
  896. struct hd_geometry __user *loc = (struct hd_geometry __user *) arg;
  897. struct ubd *dev = inode->i_bdev->bd_disk->private_data;
  898. struct hd_driveid ubd_id = {
  899. .cyls = 0,
  900. .heads = 128,
  901. .sectors = 32,
  902. };
  903. switch (cmd) {
  904. struct hd_geometry g;
  905. struct cdrom_volctrl volume;
  906. case HDIO_GETGEO:
  907. if(!loc) return(-EINVAL);
  908. g.heads = 128;
  909. g.sectors = 32;
  910. g.cylinders = dev->size / (128 * 32 * 512);
  911. g.start = get_start_sect(inode->i_bdev);
  912. return(copy_to_user(loc, &g, sizeof(g)) ? -EFAULT : 0);
  913. case HDIO_GET_IDENTITY:
  914. ubd_id.cyls = dev->size / (128 * 32 * 512);
  915. if(copy_to_user((char __user *) arg, (char *) &ubd_id,
  916. sizeof(ubd_id)))
  917. return(-EFAULT);
  918. return(0);
  919. case CDROMVOLREAD:
  920. if(copy_from_user(&volume, (char __user *) arg, sizeof(volume)))
  921. return(-EFAULT);
  922. volume.channel0 = 255;
  923. volume.channel1 = 255;
  924. volume.channel2 = 255;
  925. volume.channel3 = 255;
  926. if(copy_to_user((char __user *) arg, &volume, sizeof(volume)))
  927. return(-EFAULT);
  928. return(0);
  929. }
  930. return(-EINVAL);
  931. }
  932. static int same_backing_files(char *from_cmdline, char *from_cow, char *cow)
  933. {
  934. struct uml_stat buf1, buf2;
  935. int err;
  936. if(from_cmdline == NULL) return(1);
  937. if(!strcmp(from_cmdline, from_cow)) return(1);
  938. err = os_stat_file(from_cmdline, &buf1);
  939. if(err < 0){
  940. printk("Couldn't stat '%s', err = %d\n", from_cmdline, -err);
  941. return(1);
  942. }
  943. err = os_stat_file(from_cow, &buf2);
  944. if(err < 0){
  945. printk("Couldn't stat '%s', err = %d\n", from_cow, -err);
  946. return(1);
  947. }
  948. if((buf1.ust_dev == buf2.ust_dev) && (buf1.ust_ino == buf2.ust_ino))
  949. return(1);
  950. printk("Backing file mismatch - \"%s\" requested,\n"
  951. "\"%s\" specified in COW header of \"%s\"\n",
  952. from_cmdline, from_cow, cow);
  953. return(0);
  954. }
  955. static int backing_file_mismatch(char *file, __u64 size, time_t mtime)
  956. {
  957. unsigned long modtime;
  958. long long actual;
  959. int err;
  960. err = os_file_modtime(file, &modtime);
  961. if(err < 0){
  962. printk("Failed to get modification time of backing file "
  963. "\"%s\", err = %d\n", file, -err);
  964. return(err);
  965. }
  966. err = os_file_size(file, &actual);
  967. if(err < 0){
  968. printk("Failed to get size of backing file \"%s\", "
  969. "err = %d\n", file, -err);
  970. return(err);
  971. }
  972. if(actual != size){
  973. /*__u64 can be a long on AMD64 and with %lu GCC complains; so
  974. * the typecast.*/
  975. printk("Size mismatch (%llu vs %llu) of COW header vs backing "
  976. "file\n", (unsigned long long) size, actual);
  977. return(-EINVAL);
  978. }
  979. if(modtime != mtime){
  980. printk("mtime mismatch (%ld vs %ld) of COW header vs backing "
  981. "file\n", mtime, modtime);
  982. return(-EINVAL);
  983. }
  984. return(0);
  985. }
  986. int read_cow_bitmap(int fd, void *buf, int offset, int len)
  987. {
  988. int err;
  989. err = os_seek_file(fd, offset);
  990. if(err < 0)
  991. return(err);
  992. err = os_read_file(fd, buf, len);
  993. if(err < 0)
  994. return(err);
  995. return(0);
  996. }
  997. int open_ubd_file(char *file, struct openflags *openflags,
  998. char **backing_file_out, int *bitmap_offset_out,
  999. unsigned long *bitmap_len_out, int *data_offset_out,
  1000. int *create_cow_out)
  1001. {
  1002. time_t mtime;
  1003. unsigned long long size;
  1004. __u32 version, align;
  1005. char *backing_file;
  1006. int fd, err, sectorsize, same, mode = 0644;
  1007. fd = os_open_file(file, *openflags, mode);
  1008. if(fd < 0){
  1009. if((fd == -ENOENT) && (create_cow_out != NULL))
  1010. *create_cow_out = 1;
  1011. if(!openflags->w ||
  1012. ((fd != -EROFS) && (fd != -EACCES))) return(fd);
  1013. openflags->w = 0;
  1014. fd = os_open_file(file, *openflags, mode);
  1015. if(fd < 0)
  1016. return(fd);
  1017. }
  1018. err = os_lock_file(fd, openflags->w);
  1019. if(err < 0){
  1020. printk("Failed to lock '%s', err = %d\n", file, -err);
  1021. goto out_close;
  1022. }
  1023. if(backing_file_out == NULL) return(fd);
  1024. err = read_cow_header(file_reader, &fd, &version, &backing_file, &mtime,
  1025. &size, &sectorsize, &align, bitmap_offset_out);
  1026. if(err && (*backing_file_out != NULL)){
  1027. printk("Failed to read COW header from COW file \"%s\", "
  1028. "errno = %d\n", file, -err);
  1029. goto out_close;
  1030. }
  1031. if(err) return(fd);
  1032. if(backing_file_out == NULL) return(fd);
  1033. same = same_backing_files(*backing_file_out, backing_file, file);
  1034. if(!same && !backing_file_mismatch(*backing_file_out, size, mtime)){
  1035. printk("Switching backing file to '%s'\n", *backing_file_out);
  1036. err = write_cow_header(file, fd, *backing_file_out,
  1037. sectorsize, align, &size);
  1038. if(err){
  1039. printk("Switch failed, errno = %d\n", -err);
  1040. return(err);
  1041. }
  1042. }
  1043. else {
  1044. *backing_file_out = backing_file;
  1045. err = backing_file_mismatch(*backing_file_out, size, mtime);
  1046. if(err) goto out_close;
  1047. }
  1048. cow_sizes(version, size, sectorsize, align, *bitmap_offset_out,
  1049. bitmap_len_out, data_offset_out);
  1050. return(fd);
  1051. out_close:
  1052. os_close_file(fd);
  1053. return(err);
  1054. }
  1055. int create_cow_file(char *cow_file, char *backing_file, struct openflags flags,
  1056. int sectorsize, int alignment, int *bitmap_offset_out,
  1057. unsigned long *bitmap_len_out, int *data_offset_out)
  1058. {
  1059. int err, fd;
  1060. flags.c = 1;
  1061. fd = open_ubd_file(cow_file, &flags, NULL, NULL, NULL, NULL, NULL);
  1062. if(fd < 0){
  1063. err = fd;
  1064. printk("Open of COW file '%s' failed, errno = %d\n", cow_file,
  1065. -err);
  1066. goto out;
  1067. }
  1068. err = init_cow_file(fd, cow_file, backing_file, sectorsize, alignment,
  1069. bitmap_offset_out, bitmap_len_out,
  1070. data_offset_out);
  1071. if(!err)
  1072. return(fd);
  1073. os_close_file(fd);
  1074. out:
  1075. return(err);
  1076. }
  1077. static int update_bitmap(struct io_thread_req *req)
  1078. {
  1079. int n;
  1080. if(req->cow_offset == -1)
  1081. return(0);
  1082. n = os_seek_file(req->fds[1], req->cow_offset);
  1083. if(n < 0){
  1084. printk("do_io - bitmap lseek failed : err = %d\n", -n);
  1085. return(1);
  1086. }
  1087. n = os_write_file(req->fds[1], &req->bitmap_words,
  1088. sizeof(req->bitmap_words));
  1089. if(n != sizeof(req->bitmap_words)){
  1090. printk("do_io - bitmap update failed, err = %d fd = %d\n", -n,
  1091. req->fds[1]);
  1092. return(1);
  1093. }
  1094. return(0);
  1095. }
  1096. void do_io(struct io_thread_req *req)
  1097. {
  1098. char *buf;
  1099. unsigned long len;
  1100. int n, nsectors, start, end, bit;
  1101. int err;
  1102. __u64 off;
  1103. nsectors = req->length / req->sectorsize;
  1104. start = 0;
  1105. do {
  1106. bit = ubd_test_bit(start, (unsigned char *) &req->sector_mask);
  1107. end = start;
  1108. while((end < nsectors) &&
  1109. (ubd_test_bit(end, (unsigned char *)
  1110. &req->sector_mask) == bit))
  1111. end++;
  1112. off = req->offset + req->offsets[bit] +
  1113. start * req->sectorsize;
  1114. len = (end - start) * req->sectorsize;
  1115. buf = &req->buffer[start * req->sectorsize];
  1116. err = os_seek_file(req->fds[bit], off);
  1117. if(err < 0){
  1118. printk("do_io - lseek failed : err = %d\n", -err);
  1119. req->error = 1;
  1120. return;
  1121. }
  1122. if(req->op == UBD_READ){
  1123. n = 0;
  1124. do {
  1125. buf = &buf[n];
  1126. len -= n;
  1127. n = os_read_file(req->fds[bit], buf, len);
  1128. if (n < 0) {
  1129. printk("do_io - read failed, err = %d "
  1130. "fd = %d\n", -n, req->fds[bit]);
  1131. req->error = 1;
  1132. return;
  1133. }
  1134. } while((n < len) && (n != 0));
  1135. if (n < len) memset(&buf[n], 0, len - n);
  1136. } else {
  1137. n = os_write_file(req->fds[bit], buf, len);
  1138. if(n != len){
  1139. printk("do_io - write failed err = %d "
  1140. "fd = %d\n", -n, req->fds[bit]);
  1141. req->error = 1;
  1142. return;
  1143. }
  1144. }
  1145. start = end;
  1146. } while(start < nsectors);
  1147. req->error = update_bitmap(req);
  1148. }
  1149. /* Changed in start_io_thread, which is serialized by being called only
  1150. * from ubd_init, which is an initcall.
  1151. */
  1152. int kernel_fd = -1;
  1153. /* Only changed by the io thread */
  1154. int io_count = 0;
  1155. int io_thread(void *arg)
  1156. {
  1157. struct io_thread_req req;
  1158. int n;
  1159. ignore_sigwinch_sig();
  1160. while(1){
  1161. n = os_read_file(kernel_fd, &req, sizeof(req));
  1162. if(n != sizeof(req)){
  1163. if(n < 0)
  1164. printk("io_thread - read failed, fd = %d, "
  1165. "err = %d\n", kernel_fd, -n);
  1166. else {
  1167. printk("io_thread - short read, fd = %d, "
  1168. "length = %d\n", kernel_fd, n);
  1169. }
  1170. continue;
  1171. }
  1172. io_count++;
  1173. do_io(&req);
  1174. n = os_write_file(kernel_fd, &req, sizeof(req));
  1175. if(n != sizeof(req))
  1176. printk("io_thread - write failed, fd = %d, err = %d\n",
  1177. kernel_fd, -n);
  1178. }
  1179. }
  1180. /*
  1181. * Overrides for Emacs so that we follow Linus's tabbing style.
  1182. * Emacs will notice this stuff at the end of the file and automatically
  1183. * adjust the settings for this buffer only. This must remain at the end
  1184. * of the file.
  1185. * ---------------------------------------------------------------------------
  1186. * Local variables:
  1187. * c-file-style: "linux"
  1188. * End:
  1189. */