ubd_kern.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395
  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. if(dev->file == NULL)
  575. return(-ENODEV);
  576. if (ubd_open_dev(dev))
  577. return(-ENODEV);
  578. err = ubd_file_size(dev, &dev->size);
  579. if(err < 0)
  580. return(err);
  581. dev->size = ROUND_BLOCK(dev->size);
  582. err = ubd_new_disk(MAJOR_NR, dev->size, n, &ubd_gendisk[n]);
  583. if(err)
  584. return(err);
  585. if(fake_major != MAJOR_NR)
  586. ubd_new_disk(fake_major, dev->size, n,
  587. &fake_gendisk[n]);
  588. /* perhaps this should also be under the "if (fake_major)" above */
  589. /* using the fake_disk->disk_name and also the fakehd_set name */
  590. if (fake_ide)
  591. make_ide_entries(ubd_gendisk[n]->disk_name);
  592. ubd_close(dev);
  593. return 0;
  594. }
  595. static int ubd_config(char *str)
  596. {
  597. int n, err;
  598. str = uml_strdup(str);
  599. if(str == NULL){
  600. printk(KERN_ERR "ubd_config failed to strdup string\n");
  601. return(1);
  602. }
  603. err = ubd_setup_common(str, &n);
  604. if(err){
  605. kfree(str);
  606. return(-1);
  607. }
  608. if(n == -1) return(0);
  609. spin_lock(&ubd_lock);
  610. err = ubd_add(n);
  611. if(err)
  612. ubd_dev[n].file = NULL;
  613. spin_unlock(&ubd_lock);
  614. return(err);
  615. }
  616. static int ubd_get_config(char *name, char *str, int size, char **error_out)
  617. {
  618. struct ubd *dev;
  619. int n, len = 0;
  620. n = parse_unit(&name);
  621. if((n >= MAX_DEV) || (n < 0)){
  622. *error_out = "ubd_get_config : device number out of range";
  623. return(-1);
  624. }
  625. dev = &ubd_dev[n];
  626. spin_lock(&ubd_lock);
  627. if(dev->file == NULL){
  628. CONFIG_CHUNK(str, size, len, "", 1);
  629. goto out;
  630. }
  631. CONFIG_CHUNK(str, size, len, dev->file, 0);
  632. if(dev->cow.file != NULL){
  633. CONFIG_CHUNK(str, size, len, ",", 0);
  634. CONFIG_CHUNK(str, size, len, dev->cow.file, 1);
  635. }
  636. else CONFIG_CHUNK(str, size, len, "", 1);
  637. out:
  638. spin_unlock(&ubd_lock);
  639. return(len);
  640. }
  641. static int ubd_id(char **str, int *start_out, int *end_out)
  642. {
  643. int n;
  644. n = parse_unit(str);
  645. *start_out = 0;
  646. *end_out = MAX_DEV - 1;
  647. return n;
  648. }
  649. static int ubd_remove(int n)
  650. {
  651. struct ubd *dev;
  652. int err = -ENODEV;
  653. spin_lock(&ubd_lock);
  654. if(ubd_gendisk[n] == NULL)
  655. goto out;
  656. dev = &ubd_dev[n];
  657. if(dev->file == NULL)
  658. goto out;
  659. /* you cannot remove a open disk */
  660. err = -EBUSY;
  661. if(dev->count > 0)
  662. goto out;
  663. del_gendisk(ubd_gendisk[n]);
  664. put_disk(ubd_gendisk[n]);
  665. ubd_gendisk[n] = NULL;
  666. if(fake_gendisk[n] != NULL){
  667. del_gendisk(fake_gendisk[n]);
  668. put_disk(fake_gendisk[n]);
  669. fake_gendisk[n] = NULL;
  670. }
  671. platform_device_unregister(&dev->pdev);
  672. *dev = ((struct ubd) DEFAULT_UBD);
  673. err = 0;
  674. out:
  675. spin_unlock(&ubd_lock);
  676. return err;
  677. }
  678. static struct mc_device ubd_mc = {
  679. .name = "ubd",
  680. .config = ubd_config,
  681. .get_config = ubd_get_config,
  682. .id = ubd_id,
  683. .remove = ubd_remove,
  684. };
  685. static int ubd_mc_init(void)
  686. {
  687. mconsole_register_dev(&ubd_mc);
  688. return 0;
  689. }
  690. __initcall(ubd_mc_init);
  691. static struct device_driver ubd_driver = {
  692. .name = DRIVER_NAME,
  693. .bus = &platform_bus_type,
  694. };
  695. int ubd_init(void)
  696. {
  697. int i;
  698. devfs_mk_dir("ubd");
  699. if (register_blkdev(MAJOR_NR, "ubd"))
  700. return -1;
  701. ubd_queue = blk_init_queue(do_ubd_request, &ubd_io_lock);
  702. if (!ubd_queue) {
  703. unregister_blkdev(MAJOR_NR, "ubd");
  704. return -1;
  705. }
  706. if (fake_major != MAJOR_NR) {
  707. char name[sizeof("ubd_nnn\0")];
  708. snprintf(name, sizeof(name), "ubd_%d", fake_major);
  709. devfs_mk_dir(name);
  710. if (register_blkdev(fake_major, "ubd"))
  711. return -1;
  712. }
  713. driver_register(&ubd_driver);
  714. for (i = 0; i < MAX_DEV; i++)
  715. ubd_add(i);
  716. return 0;
  717. }
  718. late_initcall(ubd_init);
  719. int ubd_driver_init(void){
  720. unsigned long stack;
  721. int err;
  722. /* Set by CONFIG_BLK_DEV_UBD_SYNC or ubd=sync.*/
  723. if(global_openflags.s){
  724. printk(KERN_INFO "ubd: Synchronous mode\n");
  725. /* Letting ubd=sync be like using ubd#s= instead of ubd#= is
  726. * enough. So use anyway the io thread. */
  727. }
  728. stack = alloc_stack(0, 0);
  729. io_pid = start_io_thread(stack + PAGE_SIZE - sizeof(void *),
  730. &thread_fd);
  731. if(io_pid < 0){
  732. printk(KERN_ERR
  733. "ubd : Failed to start I/O thread (errno = %d) - "
  734. "falling back to synchronous I/O\n", -io_pid);
  735. io_pid = -1;
  736. return(0);
  737. }
  738. err = um_request_irq(UBD_IRQ, thread_fd, IRQ_READ, ubd_intr,
  739. SA_INTERRUPT, "ubd", ubd_dev);
  740. if(err != 0)
  741. printk(KERN_ERR "um_request_irq failed - errno = %d\n", -err);
  742. return(err);
  743. }
  744. device_initcall(ubd_driver_init);
  745. static int ubd_open(struct inode *inode, struct file *filp)
  746. {
  747. struct gendisk *disk = inode->i_bdev->bd_disk;
  748. struct ubd *dev = disk->private_data;
  749. int err = 0;
  750. if(dev->count == 0){
  751. err = ubd_open_dev(dev);
  752. if(err){
  753. printk(KERN_ERR "%s: Can't open \"%s\": errno = %d\n",
  754. disk->disk_name, dev->file, -err);
  755. goto out;
  756. }
  757. }
  758. dev->count++;
  759. set_disk_ro(disk, !dev->openflags.w);
  760. /* This should no more be needed. And it didn't work anyway to exclude
  761. * read-write remounting of filesystems.*/
  762. /*if((filp->f_mode & FMODE_WRITE) && !dev->openflags.w){
  763. if(--dev->count == 0) ubd_close(dev);
  764. err = -EROFS;
  765. }*/
  766. out:
  767. return(err);
  768. }
  769. static int ubd_release(struct inode * inode, struct file * file)
  770. {
  771. struct gendisk *disk = inode->i_bdev->bd_disk;
  772. struct ubd *dev = disk->private_data;
  773. if(--dev->count == 0)
  774. ubd_close(dev);
  775. return(0);
  776. }
  777. static void cowify_bitmap(__u64 io_offset, int length, unsigned long *cow_mask,
  778. __u64 *cow_offset, unsigned long *bitmap,
  779. __u64 bitmap_offset, unsigned long *bitmap_words,
  780. __u64 bitmap_len)
  781. {
  782. __u64 sector = io_offset >> 9;
  783. int i, update_bitmap = 0;
  784. for(i = 0; i < length >> 9; i++){
  785. if(cow_mask != NULL)
  786. ubd_set_bit(i, (unsigned char *) cow_mask);
  787. if(ubd_test_bit(sector + i, (unsigned char *) bitmap))
  788. continue;
  789. update_bitmap = 1;
  790. ubd_set_bit(sector + i, (unsigned char *) bitmap);
  791. }
  792. if(!update_bitmap)
  793. return;
  794. *cow_offset = sector / (sizeof(unsigned long) * 8);
  795. /* This takes care of the case where we're exactly at the end of the
  796. * device, and *cow_offset + 1 is off the end. So, just back it up
  797. * by one word. Thanks to Lynn Kerby for the fix and James McMechan
  798. * for the original diagnosis.
  799. */
  800. if(*cow_offset == ((bitmap_len + sizeof(unsigned long) - 1) /
  801. sizeof(unsigned long) - 1))
  802. (*cow_offset)--;
  803. bitmap_words[0] = bitmap[*cow_offset];
  804. bitmap_words[1] = bitmap[*cow_offset + 1];
  805. *cow_offset *= sizeof(unsigned long);
  806. *cow_offset += bitmap_offset;
  807. }
  808. static void cowify_req(struct io_thread_req *req, unsigned long *bitmap,
  809. __u64 bitmap_offset, __u64 bitmap_len)
  810. {
  811. __u64 sector = req->offset >> 9;
  812. int i;
  813. if(req->length > (sizeof(req->sector_mask) * 8) << 9)
  814. panic("Operation too long");
  815. if(req->op == UBD_READ) {
  816. for(i = 0; i < req->length >> 9; i++){
  817. if(ubd_test_bit(sector + i, (unsigned char *) bitmap))
  818. ubd_set_bit(i, (unsigned char *)
  819. &req->sector_mask);
  820. }
  821. }
  822. else cowify_bitmap(req->offset, req->length, &req->sector_mask,
  823. &req->cow_offset, bitmap, bitmap_offset,
  824. req->bitmap_words, bitmap_len);
  825. }
  826. /* Called with ubd_io_lock held */
  827. static int prepare_request(struct request *req, struct io_thread_req *io_req)
  828. {
  829. struct gendisk *disk = req->rq_disk;
  830. struct ubd *dev = disk->private_data;
  831. __u64 offset;
  832. int len;
  833. if(req->rq_status == RQ_INACTIVE) return(1);
  834. /* This should be impossible now */
  835. if((rq_data_dir(req) == WRITE) && !dev->openflags.w){
  836. printk("Write attempted on readonly ubd device %s\n",
  837. disk->disk_name);
  838. end_request(req, 0);
  839. return(1);
  840. }
  841. offset = ((__u64) req->sector) << 9;
  842. len = req->current_nr_sectors << 9;
  843. io_req->fds[0] = (dev->cow.file != NULL) ? dev->cow.fd : dev->fd;
  844. io_req->fds[1] = dev->fd;
  845. io_req->cow_offset = -1;
  846. io_req->offset = offset;
  847. io_req->length = len;
  848. io_req->error = 0;
  849. io_req->sector_mask = 0;
  850. io_req->op = (rq_data_dir(req) == READ) ? UBD_READ : UBD_WRITE;
  851. io_req->offsets[0] = 0;
  852. io_req->offsets[1] = dev->cow.data_offset;
  853. io_req->buffer = req->buffer;
  854. io_req->sectorsize = 1 << 9;
  855. if(dev->cow.file != NULL)
  856. cowify_req(io_req, dev->cow.bitmap, dev->cow.bitmap_offset,
  857. dev->cow.bitmap_len);
  858. return(0);
  859. }
  860. /* Called with ubd_io_lock held */
  861. static void do_ubd_request(request_queue_t *q)
  862. {
  863. struct io_thread_req io_req;
  864. struct request *req;
  865. int err, n;
  866. if(thread_fd == -1){
  867. while((req = elv_next_request(q)) != NULL){
  868. err = prepare_request(req, &io_req);
  869. if(!err){
  870. do_io(&io_req);
  871. __ubd_finish(req, io_req.error);
  872. }
  873. }
  874. }
  875. else {
  876. if(do_ubd || (req = elv_next_request(q)) == NULL)
  877. return;
  878. err = prepare_request(req, &io_req);
  879. if(!err){
  880. do_ubd = ubd_handler;
  881. n = os_write_file(thread_fd, (char *) &io_req,
  882. sizeof(io_req));
  883. if(n != sizeof(io_req))
  884. printk("write to io thread failed, "
  885. "errno = %d\n", -n);
  886. }
  887. }
  888. }
  889. static int ubd_ioctl(struct inode * inode, struct file * file,
  890. unsigned int cmd, unsigned long arg)
  891. {
  892. struct hd_geometry __user *loc = (struct hd_geometry __user *) arg;
  893. struct ubd *dev = inode->i_bdev->bd_disk->private_data;
  894. struct hd_driveid ubd_id = {
  895. .cyls = 0,
  896. .heads = 128,
  897. .sectors = 32,
  898. };
  899. switch (cmd) {
  900. struct hd_geometry g;
  901. struct cdrom_volctrl volume;
  902. case HDIO_GETGEO:
  903. if(!loc) return(-EINVAL);
  904. g.heads = 128;
  905. g.sectors = 32;
  906. g.cylinders = dev->size / (128 * 32 * 512);
  907. g.start = get_start_sect(inode->i_bdev);
  908. return(copy_to_user(loc, &g, sizeof(g)) ? -EFAULT : 0);
  909. case HDIO_GET_IDENTITY:
  910. ubd_id.cyls = dev->size / (128 * 32 * 512);
  911. if(copy_to_user((char __user *) arg, (char *) &ubd_id,
  912. sizeof(ubd_id)))
  913. return(-EFAULT);
  914. return(0);
  915. case CDROMVOLREAD:
  916. if(copy_from_user(&volume, (char __user *) arg, sizeof(volume)))
  917. return(-EFAULT);
  918. volume.channel0 = 255;
  919. volume.channel1 = 255;
  920. volume.channel2 = 255;
  921. volume.channel3 = 255;
  922. if(copy_to_user((char __user *) arg, &volume, sizeof(volume)))
  923. return(-EFAULT);
  924. return(0);
  925. }
  926. return(-EINVAL);
  927. }
  928. static int same_backing_files(char *from_cmdline, char *from_cow, char *cow)
  929. {
  930. struct uml_stat buf1, buf2;
  931. int err;
  932. if(from_cmdline == NULL) return(1);
  933. if(!strcmp(from_cmdline, from_cow)) return(1);
  934. err = os_stat_file(from_cmdline, &buf1);
  935. if(err < 0){
  936. printk("Couldn't stat '%s', err = %d\n", from_cmdline, -err);
  937. return(1);
  938. }
  939. err = os_stat_file(from_cow, &buf2);
  940. if(err < 0){
  941. printk("Couldn't stat '%s', err = %d\n", from_cow, -err);
  942. return(1);
  943. }
  944. if((buf1.ust_dev == buf2.ust_dev) && (buf1.ust_ino == buf2.ust_ino))
  945. return(1);
  946. printk("Backing file mismatch - \"%s\" requested,\n"
  947. "\"%s\" specified in COW header of \"%s\"\n",
  948. from_cmdline, from_cow, cow);
  949. return(0);
  950. }
  951. static int backing_file_mismatch(char *file, __u64 size, time_t mtime)
  952. {
  953. unsigned long modtime;
  954. long long actual;
  955. int err;
  956. err = os_file_modtime(file, &modtime);
  957. if(err < 0){
  958. printk("Failed to get modification time of backing file "
  959. "\"%s\", err = %d\n", file, -err);
  960. return(err);
  961. }
  962. err = os_file_size(file, &actual);
  963. if(err < 0){
  964. printk("Failed to get size of backing file \"%s\", "
  965. "err = %d\n", file, -err);
  966. return(err);
  967. }
  968. if(actual != size){
  969. /*__u64 can be a long on AMD64 and with %lu GCC complains; so
  970. * the typecast.*/
  971. printk("Size mismatch (%llu vs %llu) of COW header vs backing "
  972. "file\n", (unsigned long long) size, actual);
  973. return(-EINVAL);
  974. }
  975. if(modtime != mtime){
  976. printk("mtime mismatch (%ld vs %ld) of COW header vs backing "
  977. "file\n", mtime, modtime);
  978. return(-EINVAL);
  979. }
  980. return(0);
  981. }
  982. int read_cow_bitmap(int fd, void *buf, int offset, int len)
  983. {
  984. int err;
  985. err = os_seek_file(fd, offset);
  986. if(err < 0)
  987. return(err);
  988. err = os_read_file(fd, buf, len);
  989. if(err < 0)
  990. return(err);
  991. return(0);
  992. }
  993. int open_ubd_file(char *file, struct openflags *openflags,
  994. char **backing_file_out, int *bitmap_offset_out,
  995. unsigned long *bitmap_len_out, int *data_offset_out,
  996. int *create_cow_out)
  997. {
  998. time_t mtime;
  999. unsigned long long size;
  1000. __u32 version, align;
  1001. char *backing_file;
  1002. int fd, err, sectorsize, same, mode = 0644;
  1003. fd = os_open_file(file, *openflags, mode);
  1004. if(fd < 0){
  1005. if((fd == -ENOENT) && (create_cow_out != NULL))
  1006. *create_cow_out = 1;
  1007. if(!openflags->w ||
  1008. ((fd != -EROFS) && (fd != -EACCES))) return(fd);
  1009. openflags->w = 0;
  1010. fd = os_open_file(file, *openflags, mode);
  1011. if(fd < 0)
  1012. return(fd);
  1013. }
  1014. err = os_lock_file(fd, openflags->w);
  1015. if(err < 0){
  1016. printk("Failed to lock '%s', err = %d\n", file, -err);
  1017. goto out_close;
  1018. }
  1019. if(backing_file_out == NULL) return(fd);
  1020. err = read_cow_header(file_reader, &fd, &version, &backing_file, &mtime,
  1021. &size, &sectorsize, &align, bitmap_offset_out);
  1022. if(err && (*backing_file_out != NULL)){
  1023. printk("Failed to read COW header from COW file \"%s\", "
  1024. "errno = %d\n", file, -err);
  1025. goto out_close;
  1026. }
  1027. if(err) return(fd);
  1028. if(backing_file_out == NULL) return(fd);
  1029. same = same_backing_files(*backing_file_out, backing_file, file);
  1030. if(!same && !backing_file_mismatch(*backing_file_out, size, mtime)){
  1031. printk("Switching backing file to '%s'\n", *backing_file_out);
  1032. err = write_cow_header(file, fd, *backing_file_out,
  1033. sectorsize, align, &size);
  1034. if(err){
  1035. printk("Switch failed, errno = %d\n", -err);
  1036. return(err);
  1037. }
  1038. }
  1039. else {
  1040. *backing_file_out = backing_file;
  1041. err = backing_file_mismatch(*backing_file_out, size, mtime);
  1042. if(err) goto out_close;
  1043. }
  1044. cow_sizes(version, size, sectorsize, align, *bitmap_offset_out,
  1045. bitmap_len_out, data_offset_out);
  1046. return(fd);
  1047. out_close:
  1048. os_close_file(fd);
  1049. return(err);
  1050. }
  1051. int create_cow_file(char *cow_file, char *backing_file, struct openflags flags,
  1052. int sectorsize, int alignment, int *bitmap_offset_out,
  1053. unsigned long *bitmap_len_out, int *data_offset_out)
  1054. {
  1055. int err, fd;
  1056. flags.c = 1;
  1057. fd = open_ubd_file(cow_file, &flags, NULL, NULL, NULL, NULL, NULL);
  1058. if(fd < 0){
  1059. err = fd;
  1060. printk("Open of COW file '%s' failed, errno = %d\n", cow_file,
  1061. -err);
  1062. goto out;
  1063. }
  1064. err = init_cow_file(fd, cow_file, backing_file, sectorsize, alignment,
  1065. bitmap_offset_out, bitmap_len_out,
  1066. data_offset_out);
  1067. if(!err)
  1068. return(fd);
  1069. os_close_file(fd);
  1070. out:
  1071. return(err);
  1072. }
  1073. static int update_bitmap(struct io_thread_req *req)
  1074. {
  1075. int n;
  1076. if(req->cow_offset == -1)
  1077. return(0);
  1078. n = os_seek_file(req->fds[1], req->cow_offset);
  1079. if(n < 0){
  1080. printk("do_io - bitmap lseek failed : err = %d\n", -n);
  1081. return(1);
  1082. }
  1083. n = os_write_file(req->fds[1], &req->bitmap_words,
  1084. sizeof(req->bitmap_words));
  1085. if(n != sizeof(req->bitmap_words)){
  1086. printk("do_io - bitmap update failed, err = %d fd = %d\n", -n,
  1087. req->fds[1]);
  1088. return(1);
  1089. }
  1090. return(0);
  1091. }
  1092. void do_io(struct io_thread_req *req)
  1093. {
  1094. char *buf;
  1095. unsigned long len;
  1096. int n, nsectors, start, end, bit;
  1097. int err;
  1098. __u64 off;
  1099. nsectors = req->length / req->sectorsize;
  1100. start = 0;
  1101. do {
  1102. bit = ubd_test_bit(start, (unsigned char *) &req->sector_mask);
  1103. end = start;
  1104. while((end < nsectors) &&
  1105. (ubd_test_bit(end, (unsigned char *)
  1106. &req->sector_mask) == bit))
  1107. end++;
  1108. off = req->offset + req->offsets[bit] +
  1109. start * req->sectorsize;
  1110. len = (end - start) * req->sectorsize;
  1111. buf = &req->buffer[start * req->sectorsize];
  1112. err = os_seek_file(req->fds[bit], off);
  1113. if(err < 0){
  1114. printk("do_io - lseek failed : err = %d\n", -err);
  1115. req->error = 1;
  1116. return;
  1117. }
  1118. if(req->op == UBD_READ){
  1119. n = 0;
  1120. do {
  1121. buf = &buf[n];
  1122. len -= n;
  1123. n = os_read_file(req->fds[bit], buf, len);
  1124. if (n < 0) {
  1125. printk("do_io - read failed, err = %d "
  1126. "fd = %d\n", -n, req->fds[bit]);
  1127. req->error = 1;
  1128. return;
  1129. }
  1130. } while((n < len) && (n != 0));
  1131. if (n < len) memset(&buf[n], 0, len - n);
  1132. } else {
  1133. n = os_write_file(req->fds[bit], buf, len);
  1134. if(n != len){
  1135. printk("do_io - write failed err = %d "
  1136. "fd = %d\n", -n, req->fds[bit]);
  1137. req->error = 1;
  1138. return;
  1139. }
  1140. }
  1141. start = end;
  1142. } while(start < nsectors);
  1143. req->error = update_bitmap(req);
  1144. }
  1145. /* Changed in start_io_thread, which is serialized by being called only
  1146. * from ubd_init, which is an initcall.
  1147. */
  1148. int kernel_fd = -1;
  1149. /* Only changed by the io thread */
  1150. int io_count = 0;
  1151. int io_thread(void *arg)
  1152. {
  1153. struct io_thread_req req;
  1154. int n;
  1155. ignore_sigwinch_sig();
  1156. while(1){
  1157. n = os_read_file(kernel_fd, &req, sizeof(req));
  1158. if(n != sizeof(req)){
  1159. if(n < 0)
  1160. printk("io_thread - read failed, fd = %d, "
  1161. "err = %d\n", kernel_fd, -n);
  1162. else {
  1163. printk("io_thread - short read, fd = %d, "
  1164. "length = %d\n", kernel_fd, n);
  1165. }
  1166. continue;
  1167. }
  1168. io_count++;
  1169. do_io(&req);
  1170. n = os_write_file(kernel_fd, &req, sizeof(req));
  1171. if(n != sizeof(req))
  1172. printk("io_thread - write failed, fd = %d, err = %d\n",
  1173. kernel_fd, -n);
  1174. }
  1175. }
  1176. /*
  1177. * Overrides for Emacs so that we follow Linus's tabbing style.
  1178. * Emacs will notice this stuff at the end of the file and automatically
  1179. * adjust the settings for this buffer only. This must remain at the end
  1180. * of the file.
  1181. * ---------------------------------------------------------------------------
  1182. * Local variables:
  1183. * c-file-style: "linux"
  1184. * End:
  1185. */