ubd_kern.c 32 KB

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