dev.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040
  1. /*
  2. FUSE: Filesystem in Userspace
  3. Copyright (C) 2001-2008 Miklos Szeredi <miklos@szeredi.hu>
  4. This program can be distributed under the terms of the GNU GPL.
  5. See the file COPYING.
  6. */
  7. #include "fuse_i.h"
  8. #include <linux/init.h>
  9. #include <linux/module.h>
  10. #include <linux/poll.h>
  11. #include <linux/uio.h>
  12. #include <linux/miscdevice.h>
  13. #include <linux/pagemap.h>
  14. #include <linux/file.h>
  15. #include <linux/slab.h>
  16. #include <linux/pipe_fs_i.h>
  17. #include <linux/swap.h>
  18. #include <linux/splice.h>
  19. MODULE_ALIAS_MISCDEV(FUSE_MINOR);
  20. MODULE_ALIAS("devname:fuse");
  21. static struct kmem_cache *fuse_req_cachep;
  22. static struct fuse_conn *fuse_get_conn(struct file *file)
  23. {
  24. /*
  25. * Lockless access is OK, because file->private data is set
  26. * once during mount and is valid until the file is released.
  27. */
  28. return file->private_data;
  29. }
  30. static void fuse_request_init(struct fuse_req *req)
  31. {
  32. memset(req, 0, sizeof(*req));
  33. INIT_LIST_HEAD(&req->list);
  34. INIT_LIST_HEAD(&req->intr_entry);
  35. init_waitqueue_head(&req->waitq);
  36. atomic_set(&req->count, 1);
  37. }
  38. struct fuse_req *fuse_request_alloc(void)
  39. {
  40. struct fuse_req *req = kmem_cache_alloc(fuse_req_cachep, GFP_KERNEL);
  41. if (req)
  42. fuse_request_init(req);
  43. return req;
  44. }
  45. EXPORT_SYMBOL_GPL(fuse_request_alloc);
  46. struct fuse_req *fuse_request_alloc_nofs(void)
  47. {
  48. struct fuse_req *req = kmem_cache_alloc(fuse_req_cachep, GFP_NOFS);
  49. if (req)
  50. fuse_request_init(req);
  51. return req;
  52. }
  53. void fuse_request_free(struct fuse_req *req)
  54. {
  55. kmem_cache_free(fuse_req_cachep, req);
  56. }
  57. static void block_sigs(sigset_t *oldset)
  58. {
  59. sigset_t mask;
  60. siginitsetinv(&mask, sigmask(SIGKILL));
  61. sigprocmask(SIG_BLOCK, &mask, oldset);
  62. }
  63. static void restore_sigs(sigset_t *oldset)
  64. {
  65. sigprocmask(SIG_SETMASK, oldset, NULL);
  66. }
  67. static void __fuse_get_request(struct fuse_req *req)
  68. {
  69. atomic_inc(&req->count);
  70. }
  71. /* Must be called with > 1 refcount */
  72. static void __fuse_put_request(struct fuse_req *req)
  73. {
  74. BUG_ON(atomic_read(&req->count) < 2);
  75. atomic_dec(&req->count);
  76. }
  77. static void fuse_req_init_context(struct fuse_req *req)
  78. {
  79. req->in.h.uid = current_fsuid();
  80. req->in.h.gid = current_fsgid();
  81. req->in.h.pid = current->pid;
  82. }
  83. struct fuse_req *fuse_get_req(struct fuse_conn *fc)
  84. {
  85. struct fuse_req *req;
  86. sigset_t oldset;
  87. int intr;
  88. int err;
  89. atomic_inc(&fc->num_waiting);
  90. block_sigs(&oldset);
  91. intr = wait_event_interruptible(fc->blocked_waitq, !fc->blocked);
  92. restore_sigs(&oldset);
  93. err = -EINTR;
  94. if (intr)
  95. goto out;
  96. err = -ENOTCONN;
  97. if (!fc->connected)
  98. goto out;
  99. req = fuse_request_alloc();
  100. err = -ENOMEM;
  101. if (!req)
  102. goto out;
  103. fuse_req_init_context(req);
  104. req->waiting = 1;
  105. return req;
  106. out:
  107. atomic_dec(&fc->num_waiting);
  108. return ERR_PTR(err);
  109. }
  110. EXPORT_SYMBOL_GPL(fuse_get_req);
  111. /*
  112. * Return request in fuse_file->reserved_req. However that may
  113. * currently be in use. If that is the case, wait for it to become
  114. * available.
  115. */
  116. static struct fuse_req *get_reserved_req(struct fuse_conn *fc,
  117. struct file *file)
  118. {
  119. struct fuse_req *req = NULL;
  120. struct fuse_file *ff = file->private_data;
  121. do {
  122. wait_event(fc->reserved_req_waitq, ff->reserved_req);
  123. spin_lock(&fc->lock);
  124. if (ff->reserved_req) {
  125. req = ff->reserved_req;
  126. ff->reserved_req = NULL;
  127. get_file(file);
  128. req->stolen_file = file;
  129. }
  130. spin_unlock(&fc->lock);
  131. } while (!req);
  132. return req;
  133. }
  134. /*
  135. * Put stolen request back into fuse_file->reserved_req
  136. */
  137. static void put_reserved_req(struct fuse_conn *fc, struct fuse_req *req)
  138. {
  139. struct file *file = req->stolen_file;
  140. struct fuse_file *ff = file->private_data;
  141. spin_lock(&fc->lock);
  142. fuse_request_init(req);
  143. BUG_ON(ff->reserved_req);
  144. ff->reserved_req = req;
  145. wake_up_all(&fc->reserved_req_waitq);
  146. spin_unlock(&fc->lock);
  147. fput(file);
  148. }
  149. /*
  150. * Gets a requests for a file operation, always succeeds
  151. *
  152. * This is used for sending the FLUSH request, which must get to
  153. * userspace, due to POSIX locks which may need to be unlocked.
  154. *
  155. * If allocation fails due to OOM, use the reserved request in
  156. * fuse_file.
  157. *
  158. * This is very unlikely to deadlock accidentally, since the
  159. * filesystem should not have it's own file open. If deadlock is
  160. * intentional, it can still be broken by "aborting" the filesystem.
  161. */
  162. struct fuse_req *fuse_get_req_nofail(struct fuse_conn *fc, struct file *file)
  163. {
  164. struct fuse_req *req;
  165. atomic_inc(&fc->num_waiting);
  166. wait_event(fc->blocked_waitq, !fc->blocked);
  167. req = fuse_request_alloc();
  168. if (!req)
  169. req = get_reserved_req(fc, file);
  170. fuse_req_init_context(req);
  171. req->waiting = 1;
  172. return req;
  173. }
  174. void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req)
  175. {
  176. if (atomic_dec_and_test(&req->count)) {
  177. if (req->waiting)
  178. atomic_dec(&fc->num_waiting);
  179. if (req->stolen_file)
  180. put_reserved_req(fc, req);
  181. else
  182. fuse_request_free(req);
  183. }
  184. }
  185. EXPORT_SYMBOL_GPL(fuse_put_request);
  186. static unsigned len_args(unsigned numargs, struct fuse_arg *args)
  187. {
  188. unsigned nbytes = 0;
  189. unsigned i;
  190. for (i = 0; i < numargs; i++)
  191. nbytes += args[i].size;
  192. return nbytes;
  193. }
  194. static u64 fuse_get_unique(struct fuse_conn *fc)
  195. {
  196. fc->reqctr++;
  197. /* zero is special */
  198. if (fc->reqctr == 0)
  199. fc->reqctr = 1;
  200. return fc->reqctr;
  201. }
  202. static void queue_request(struct fuse_conn *fc, struct fuse_req *req)
  203. {
  204. req->in.h.len = sizeof(struct fuse_in_header) +
  205. len_args(req->in.numargs, (struct fuse_arg *) req->in.args);
  206. list_add_tail(&req->list, &fc->pending);
  207. req->state = FUSE_REQ_PENDING;
  208. if (!req->waiting) {
  209. req->waiting = 1;
  210. atomic_inc(&fc->num_waiting);
  211. }
  212. wake_up(&fc->waitq);
  213. kill_fasync(&fc->fasync, SIGIO, POLL_IN);
  214. }
  215. void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget,
  216. u64 nodeid, u64 nlookup)
  217. {
  218. forget->forget_one.nodeid = nodeid;
  219. forget->forget_one.nlookup = nlookup;
  220. spin_lock(&fc->lock);
  221. fc->forget_list_tail->next = forget;
  222. fc->forget_list_tail = forget;
  223. wake_up(&fc->waitq);
  224. kill_fasync(&fc->fasync, SIGIO, POLL_IN);
  225. spin_unlock(&fc->lock);
  226. }
  227. static void flush_bg_queue(struct fuse_conn *fc)
  228. {
  229. while (fc->active_background < fc->max_background &&
  230. !list_empty(&fc->bg_queue)) {
  231. struct fuse_req *req;
  232. req = list_entry(fc->bg_queue.next, struct fuse_req, list);
  233. list_del(&req->list);
  234. fc->active_background++;
  235. req->in.h.unique = fuse_get_unique(fc);
  236. queue_request(fc, req);
  237. }
  238. }
  239. /*
  240. * This function is called when a request is finished. Either a reply
  241. * has arrived or it was aborted (and not yet sent) or some error
  242. * occurred during communication with userspace, or the device file
  243. * was closed. The requester thread is woken up (if still waiting),
  244. * the 'end' callback is called if given, else the reference to the
  245. * request is released
  246. *
  247. * Called with fc->lock, unlocks it
  248. */
  249. static void request_end(struct fuse_conn *fc, struct fuse_req *req)
  250. __releases(fc->lock)
  251. {
  252. void (*end) (struct fuse_conn *, struct fuse_req *) = req->end;
  253. req->end = NULL;
  254. list_del(&req->list);
  255. list_del(&req->intr_entry);
  256. req->state = FUSE_REQ_FINISHED;
  257. if (req->background) {
  258. if (fc->num_background == fc->max_background) {
  259. fc->blocked = 0;
  260. wake_up_all(&fc->blocked_waitq);
  261. }
  262. if (fc->num_background == fc->congestion_threshold &&
  263. fc->connected && fc->bdi_initialized) {
  264. clear_bdi_congested(&fc->bdi, BLK_RW_SYNC);
  265. clear_bdi_congested(&fc->bdi, BLK_RW_ASYNC);
  266. }
  267. fc->num_background--;
  268. fc->active_background--;
  269. flush_bg_queue(fc);
  270. }
  271. spin_unlock(&fc->lock);
  272. wake_up(&req->waitq);
  273. if (end)
  274. end(fc, req);
  275. fuse_put_request(fc, req);
  276. }
  277. static void wait_answer_interruptible(struct fuse_conn *fc,
  278. struct fuse_req *req)
  279. __releases(fc->lock)
  280. __acquires(fc->lock)
  281. {
  282. if (signal_pending(current))
  283. return;
  284. spin_unlock(&fc->lock);
  285. wait_event_interruptible(req->waitq, req->state == FUSE_REQ_FINISHED);
  286. spin_lock(&fc->lock);
  287. }
  288. static void queue_interrupt(struct fuse_conn *fc, struct fuse_req *req)
  289. {
  290. list_add_tail(&req->intr_entry, &fc->interrupts);
  291. wake_up(&fc->waitq);
  292. kill_fasync(&fc->fasync, SIGIO, POLL_IN);
  293. }
  294. static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req)
  295. __releases(fc->lock)
  296. __acquires(fc->lock)
  297. {
  298. if (!fc->no_interrupt) {
  299. /* Any signal may interrupt this */
  300. wait_answer_interruptible(fc, req);
  301. if (req->aborted)
  302. goto aborted;
  303. if (req->state == FUSE_REQ_FINISHED)
  304. return;
  305. req->interrupted = 1;
  306. if (req->state == FUSE_REQ_SENT)
  307. queue_interrupt(fc, req);
  308. }
  309. if (!req->force) {
  310. sigset_t oldset;
  311. /* Only fatal signals may interrupt this */
  312. block_sigs(&oldset);
  313. wait_answer_interruptible(fc, req);
  314. restore_sigs(&oldset);
  315. if (req->aborted)
  316. goto aborted;
  317. if (req->state == FUSE_REQ_FINISHED)
  318. return;
  319. /* Request is not yet in userspace, bail out */
  320. if (req->state == FUSE_REQ_PENDING) {
  321. list_del(&req->list);
  322. __fuse_put_request(req);
  323. req->out.h.error = -EINTR;
  324. return;
  325. }
  326. }
  327. /*
  328. * Either request is already in userspace, or it was forced.
  329. * Wait it out.
  330. */
  331. spin_unlock(&fc->lock);
  332. wait_event(req->waitq, req->state == FUSE_REQ_FINISHED);
  333. spin_lock(&fc->lock);
  334. if (!req->aborted)
  335. return;
  336. aborted:
  337. BUG_ON(req->state != FUSE_REQ_FINISHED);
  338. if (req->locked) {
  339. /* This is uninterruptible sleep, because data is
  340. being copied to/from the buffers of req. During
  341. locked state, there mustn't be any filesystem
  342. operation (e.g. page fault), since that could lead
  343. to deadlock */
  344. spin_unlock(&fc->lock);
  345. wait_event(req->waitq, !req->locked);
  346. spin_lock(&fc->lock);
  347. }
  348. }
  349. void fuse_request_send(struct fuse_conn *fc, struct fuse_req *req)
  350. {
  351. req->isreply = 1;
  352. spin_lock(&fc->lock);
  353. if (!fc->connected)
  354. req->out.h.error = -ENOTCONN;
  355. else if (fc->conn_error)
  356. req->out.h.error = -ECONNREFUSED;
  357. else {
  358. req->in.h.unique = fuse_get_unique(fc);
  359. queue_request(fc, req);
  360. /* acquire extra reference, since request is still needed
  361. after request_end() */
  362. __fuse_get_request(req);
  363. request_wait_answer(fc, req);
  364. }
  365. spin_unlock(&fc->lock);
  366. }
  367. EXPORT_SYMBOL_GPL(fuse_request_send);
  368. static void fuse_request_send_nowait_locked(struct fuse_conn *fc,
  369. struct fuse_req *req)
  370. {
  371. req->background = 1;
  372. fc->num_background++;
  373. if (fc->num_background == fc->max_background)
  374. fc->blocked = 1;
  375. if (fc->num_background == fc->congestion_threshold &&
  376. fc->bdi_initialized) {
  377. set_bdi_congested(&fc->bdi, BLK_RW_SYNC);
  378. set_bdi_congested(&fc->bdi, BLK_RW_ASYNC);
  379. }
  380. list_add_tail(&req->list, &fc->bg_queue);
  381. flush_bg_queue(fc);
  382. }
  383. static void fuse_request_send_nowait(struct fuse_conn *fc, struct fuse_req *req)
  384. {
  385. spin_lock(&fc->lock);
  386. if (fc->connected) {
  387. fuse_request_send_nowait_locked(fc, req);
  388. spin_unlock(&fc->lock);
  389. } else {
  390. req->out.h.error = -ENOTCONN;
  391. request_end(fc, req);
  392. }
  393. }
  394. void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req)
  395. {
  396. req->isreply = 1;
  397. fuse_request_send_nowait(fc, req);
  398. }
  399. EXPORT_SYMBOL_GPL(fuse_request_send_background);
  400. static int fuse_request_send_notify_reply(struct fuse_conn *fc,
  401. struct fuse_req *req, u64 unique)
  402. {
  403. int err = -ENODEV;
  404. req->isreply = 0;
  405. req->in.h.unique = unique;
  406. spin_lock(&fc->lock);
  407. if (fc->connected) {
  408. queue_request(fc, req);
  409. err = 0;
  410. }
  411. spin_unlock(&fc->lock);
  412. return err;
  413. }
  414. /*
  415. * Called under fc->lock
  416. *
  417. * fc->connected must have been checked previously
  418. */
  419. void fuse_request_send_background_locked(struct fuse_conn *fc,
  420. struct fuse_req *req)
  421. {
  422. req->isreply = 1;
  423. fuse_request_send_nowait_locked(fc, req);
  424. }
  425. /*
  426. * Lock the request. Up to the next unlock_request() there mustn't be
  427. * anything that could cause a page-fault. If the request was already
  428. * aborted bail out.
  429. */
  430. static int lock_request(struct fuse_conn *fc, struct fuse_req *req)
  431. {
  432. int err = 0;
  433. if (req) {
  434. spin_lock(&fc->lock);
  435. if (req->aborted)
  436. err = -ENOENT;
  437. else
  438. req->locked = 1;
  439. spin_unlock(&fc->lock);
  440. }
  441. return err;
  442. }
  443. /*
  444. * Unlock request. If it was aborted during being locked, the
  445. * requester thread is currently waiting for it to be unlocked, so
  446. * wake it up.
  447. */
  448. static void unlock_request(struct fuse_conn *fc, struct fuse_req *req)
  449. {
  450. if (req) {
  451. spin_lock(&fc->lock);
  452. req->locked = 0;
  453. if (req->aborted)
  454. wake_up(&req->waitq);
  455. spin_unlock(&fc->lock);
  456. }
  457. }
  458. struct fuse_copy_state {
  459. struct fuse_conn *fc;
  460. int write;
  461. struct fuse_req *req;
  462. const struct iovec *iov;
  463. struct pipe_buffer *pipebufs;
  464. struct pipe_buffer *currbuf;
  465. struct pipe_inode_info *pipe;
  466. unsigned long nr_segs;
  467. unsigned long seglen;
  468. unsigned long addr;
  469. struct page *pg;
  470. void *mapaddr;
  471. void *buf;
  472. unsigned len;
  473. unsigned move_pages:1;
  474. };
  475. static void fuse_copy_init(struct fuse_copy_state *cs, struct fuse_conn *fc,
  476. int write,
  477. const struct iovec *iov, unsigned long nr_segs)
  478. {
  479. memset(cs, 0, sizeof(*cs));
  480. cs->fc = fc;
  481. cs->write = write;
  482. cs->iov = iov;
  483. cs->nr_segs = nr_segs;
  484. }
  485. /* Unmap and put previous page of userspace buffer */
  486. static void fuse_copy_finish(struct fuse_copy_state *cs)
  487. {
  488. if (cs->currbuf) {
  489. struct pipe_buffer *buf = cs->currbuf;
  490. if (!cs->write) {
  491. buf->ops->unmap(cs->pipe, buf, cs->mapaddr);
  492. } else {
  493. kunmap(buf->page);
  494. buf->len = PAGE_SIZE - cs->len;
  495. }
  496. cs->currbuf = NULL;
  497. cs->mapaddr = NULL;
  498. } else if (cs->mapaddr) {
  499. kunmap(cs->pg);
  500. if (cs->write) {
  501. flush_dcache_page(cs->pg);
  502. set_page_dirty_lock(cs->pg);
  503. }
  504. put_page(cs->pg);
  505. cs->mapaddr = NULL;
  506. }
  507. }
  508. /*
  509. * Get another pagefull of userspace buffer, and map it to kernel
  510. * address space, and lock request
  511. */
  512. static int fuse_copy_fill(struct fuse_copy_state *cs)
  513. {
  514. unsigned long offset;
  515. int err;
  516. unlock_request(cs->fc, cs->req);
  517. fuse_copy_finish(cs);
  518. if (cs->pipebufs) {
  519. struct pipe_buffer *buf = cs->pipebufs;
  520. if (!cs->write) {
  521. err = buf->ops->confirm(cs->pipe, buf);
  522. if (err)
  523. return err;
  524. BUG_ON(!cs->nr_segs);
  525. cs->currbuf = buf;
  526. cs->mapaddr = buf->ops->map(cs->pipe, buf, 0);
  527. cs->len = buf->len;
  528. cs->buf = cs->mapaddr + buf->offset;
  529. cs->pipebufs++;
  530. cs->nr_segs--;
  531. } else {
  532. struct page *page;
  533. if (cs->nr_segs == cs->pipe->buffers)
  534. return -EIO;
  535. page = alloc_page(GFP_HIGHUSER);
  536. if (!page)
  537. return -ENOMEM;
  538. buf->page = page;
  539. buf->offset = 0;
  540. buf->len = 0;
  541. cs->currbuf = buf;
  542. cs->mapaddr = kmap(page);
  543. cs->buf = cs->mapaddr;
  544. cs->len = PAGE_SIZE;
  545. cs->pipebufs++;
  546. cs->nr_segs++;
  547. }
  548. } else {
  549. if (!cs->seglen) {
  550. BUG_ON(!cs->nr_segs);
  551. cs->seglen = cs->iov[0].iov_len;
  552. cs->addr = (unsigned long) cs->iov[0].iov_base;
  553. cs->iov++;
  554. cs->nr_segs--;
  555. }
  556. err = get_user_pages_fast(cs->addr, 1, cs->write, &cs->pg);
  557. if (err < 0)
  558. return err;
  559. BUG_ON(err != 1);
  560. offset = cs->addr % PAGE_SIZE;
  561. cs->mapaddr = kmap(cs->pg);
  562. cs->buf = cs->mapaddr + offset;
  563. cs->len = min(PAGE_SIZE - offset, cs->seglen);
  564. cs->seglen -= cs->len;
  565. cs->addr += cs->len;
  566. }
  567. return lock_request(cs->fc, cs->req);
  568. }
  569. /* Do as much copy to/from userspace buffer as we can */
  570. static int fuse_copy_do(struct fuse_copy_state *cs, void **val, unsigned *size)
  571. {
  572. unsigned ncpy = min(*size, cs->len);
  573. if (val) {
  574. if (cs->write)
  575. memcpy(cs->buf, *val, ncpy);
  576. else
  577. memcpy(*val, cs->buf, ncpy);
  578. *val += ncpy;
  579. }
  580. *size -= ncpy;
  581. cs->len -= ncpy;
  582. cs->buf += ncpy;
  583. return ncpy;
  584. }
  585. static int fuse_check_page(struct page *page)
  586. {
  587. if (page_mapcount(page) ||
  588. page->mapping != NULL ||
  589. page_count(page) != 1 ||
  590. (page->flags & PAGE_FLAGS_CHECK_AT_PREP &
  591. ~(1 << PG_locked |
  592. 1 << PG_referenced |
  593. 1 << PG_uptodate |
  594. 1 << PG_lru |
  595. 1 << PG_active |
  596. 1 << PG_reclaim))) {
  597. printk(KERN_WARNING "fuse: trying to steal weird page\n");
  598. printk(KERN_WARNING " page=%p index=%li flags=%08lx, count=%i, mapcount=%i, mapping=%p\n", page, page->index, page->flags, page_count(page), page_mapcount(page), page->mapping);
  599. return 1;
  600. }
  601. return 0;
  602. }
  603. static int fuse_try_move_page(struct fuse_copy_state *cs, struct page **pagep)
  604. {
  605. int err;
  606. struct page *oldpage = *pagep;
  607. struct page *newpage;
  608. struct pipe_buffer *buf = cs->pipebufs;
  609. struct address_space *mapping;
  610. pgoff_t index;
  611. unlock_request(cs->fc, cs->req);
  612. fuse_copy_finish(cs);
  613. err = buf->ops->confirm(cs->pipe, buf);
  614. if (err)
  615. return err;
  616. BUG_ON(!cs->nr_segs);
  617. cs->currbuf = buf;
  618. cs->len = buf->len;
  619. cs->pipebufs++;
  620. cs->nr_segs--;
  621. if (cs->len != PAGE_SIZE)
  622. goto out_fallback;
  623. if (buf->ops->steal(cs->pipe, buf) != 0)
  624. goto out_fallback;
  625. newpage = buf->page;
  626. if (WARN_ON(!PageUptodate(newpage)))
  627. return -EIO;
  628. ClearPageMappedToDisk(newpage);
  629. if (fuse_check_page(newpage) != 0)
  630. goto out_fallback_unlock;
  631. mapping = oldpage->mapping;
  632. index = oldpage->index;
  633. /*
  634. * This is a new and locked page, it shouldn't be mapped or
  635. * have any special flags on it
  636. */
  637. if (WARN_ON(page_mapped(oldpage)))
  638. goto out_fallback_unlock;
  639. if (WARN_ON(page_has_private(oldpage)))
  640. goto out_fallback_unlock;
  641. if (WARN_ON(PageDirty(oldpage) || PageWriteback(oldpage)))
  642. goto out_fallback_unlock;
  643. if (WARN_ON(PageMlocked(oldpage)))
  644. goto out_fallback_unlock;
  645. err = replace_page_cache_page(oldpage, newpage, GFP_KERNEL);
  646. if (err) {
  647. unlock_page(newpage);
  648. return err;
  649. }
  650. page_cache_get(newpage);
  651. if (!(buf->flags & PIPE_BUF_FLAG_LRU))
  652. lru_cache_add_file(newpage);
  653. err = 0;
  654. spin_lock(&cs->fc->lock);
  655. if (cs->req->aborted)
  656. err = -ENOENT;
  657. else
  658. *pagep = newpage;
  659. spin_unlock(&cs->fc->lock);
  660. if (err) {
  661. unlock_page(newpage);
  662. page_cache_release(newpage);
  663. return err;
  664. }
  665. unlock_page(oldpage);
  666. page_cache_release(oldpage);
  667. cs->len = 0;
  668. return 0;
  669. out_fallback_unlock:
  670. unlock_page(newpage);
  671. out_fallback:
  672. cs->mapaddr = buf->ops->map(cs->pipe, buf, 1);
  673. cs->buf = cs->mapaddr + buf->offset;
  674. err = lock_request(cs->fc, cs->req);
  675. if (err)
  676. return err;
  677. return 1;
  678. }
  679. static int fuse_ref_page(struct fuse_copy_state *cs, struct page *page,
  680. unsigned offset, unsigned count)
  681. {
  682. struct pipe_buffer *buf;
  683. if (cs->nr_segs == cs->pipe->buffers)
  684. return -EIO;
  685. unlock_request(cs->fc, cs->req);
  686. fuse_copy_finish(cs);
  687. buf = cs->pipebufs;
  688. page_cache_get(page);
  689. buf->page = page;
  690. buf->offset = offset;
  691. buf->len = count;
  692. cs->pipebufs++;
  693. cs->nr_segs++;
  694. cs->len = 0;
  695. return 0;
  696. }
  697. /*
  698. * Copy a page in the request to/from the userspace buffer. Must be
  699. * done atomically
  700. */
  701. static int fuse_copy_page(struct fuse_copy_state *cs, struct page **pagep,
  702. unsigned offset, unsigned count, int zeroing)
  703. {
  704. int err;
  705. struct page *page = *pagep;
  706. if (page && zeroing && count < PAGE_SIZE)
  707. clear_highpage(page);
  708. while (count) {
  709. if (cs->write && cs->pipebufs && page) {
  710. return fuse_ref_page(cs, page, offset, count);
  711. } else if (!cs->len) {
  712. if (cs->move_pages && page &&
  713. offset == 0 && count == PAGE_SIZE) {
  714. err = fuse_try_move_page(cs, pagep);
  715. if (err <= 0)
  716. return err;
  717. } else {
  718. err = fuse_copy_fill(cs);
  719. if (err)
  720. return err;
  721. }
  722. }
  723. if (page) {
  724. void *mapaddr = kmap_atomic(page, KM_USER0);
  725. void *buf = mapaddr + offset;
  726. offset += fuse_copy_do(cs, &buf, &count);
  727. kunmap_atomic(mapaddr, KM_USER0);
  728. } else
  729. offset += fuse_copy_do(cs, NULL, &count);
  730. }
  731. if (page && !cs->write)
  732. flush_dcache_page(page);
  733. return 0;
  734. }
  735. /* Copy pages in the request to/from userspace buffer */
  736. static int fuse_copy_pages(struct fuse_copy_state *cs, unsigned nbytes,
  737. int zeroing)
  738. {
  739. unsigned i;
  740. struct fuse_req *req = cs->req;
  741. unsigned offset = req->page_offset;
  742. unsigned count = min(nbytes, (unsigned) PAGE_SIZE - offset);
  743. for (i = 0; i < req->num_pages && (nbytes || zeroing); i++) {
  744. int err;
  745. err = fuse_copy_page(cs, &req->pages[i], offset, count,
  746. zeroing);
  747. if (err)
  748. return err;
  749. nbytes -= count;
  750. count = min(nbytes, (unsigned) PAGE_SIZE);
  751. offset = 0;
  752. }
  753. return 0;
  754. }
  755. /* Copy a single argument in the request to/from userspace buffer */
  756. static int fuse_copy_one(struct fuse_copy_state *cs, void *val, unsigned size)
  757. {
  758. while (size) {
  759. if (!cs->len) {
  760. int err = fuse_copy_fill(cs);
  761. if (err)
  762. return err;
  763. }
  764. fuse_copy_do(cs, &val, &size);
  765. }
  766. return 0;
  767. }
  768. /* Copy request arguments to/from userspace buffer */
  769. static int fuse_copy_args(struct fuse_copy_state *cs, unsigned numargs,
  770. unsigned argpages, struct fuse_arg *args,
  771. int zeroing)
  772. {
  773. int err = 0;
  774. unsigned i;
  775. for (i = 0; !err && i < numargs; i++) {
  776. struct fuse_arg *arg = &args[i];
  777. if (i == numargs - 1 && argpages)
  778. err = fuse_copy_pages(cs, arg->size, zeroing);
  779. else
  780. err = fuse_copy_one(cs, arg->value, arg->size);
  781. }
  782. return err;
  783. }
  784. static int forget_pending(struct fuse_conn *fc)
  785. {
  786. return fc->forget_list_head.next != NULL;
  787. }
  788. static int request_pending(struct fuse_conn *fc)
  789. {
  790. return !list_empty(&fc->pending) || !list_empty(&fc->interrupts) ||
  791. forget_pending(fc);
  792. }
  793. /* Wait until a request is available on the pending list */
  794. static void request_wait(struct fuse_conn *fc)
  795. __releases(fc->lock)
  796. __acquires(fc->lock)
  797. {
  798. DECLARE_WAITQUEUE(wait, current);
  799. add_wait_queue_exclusive(&fc->waitq, &wait);
  800. while (fc->connected && !request_pending(fc)) {
  801. set_current_state(TASK_INTERRUPTIBLE);
  802. if (signal_pending(current))
  803. break;
  804. spin_unlock(&fc->lock);
  805. schedule();
  806. spin_lock(&fc->lock);
  807. }
  808. set_current_state(TASK_RUNNING);
  809. remove_wait_queue(&fc->waitq, &wait);
  810. }
  811. /*
  812. * Transfer an interrupt request to userspace
  813. *
  814. * Unlike other requests this is assembled on demand, without a need
  815. * to allocate a separate fuse_req structure.
  816. *
  817. * Called with fc->lock held, releases it
  818. */
  819. static int fuse_read_interrupt(struct fuse_conn *fc, struct fuse_copy_state *cs,
  820. size_t nbytes, struct fuse_req *req)
  821. __releases(fc->lock)
  822. {
  823. struct fuse_in_header ih;
  824. struct fuse_interrupt_in arg;
  825. unsigned reqsize = sizeof(ih) + sizeof(arg);
  826. int err;
  827. list_del_init(&req->intr_entry);
  828. req->intr_unique = fuse_get_unique(fc);
  829. memset(&ih, 0, sizeof(ih));
  830. memset(&arg, 0, sizeof(arg));
  831. ih.len = reqsize;
  832. ih.opcode = FUSE_INTERRUPT;
  833. ih.unique = req->intr_unique;
  834. arg.unique = req->in.h.unique;
  835. spin_unlock(&fc->lock);
  836. if (nbytes < reqsize)
  837. return -EINVAL;
  838. err = fuse_copy_one(cs, &ih, sizeof(ih));
  839. if (!err)
  840. err = fuse_copy_one(cs, &arg, sizeof(arg));
  841. fuse_copy_finish(cs);
  842. return err ? err : reqsize;
  843. }
  844. static struct fuse_forget_link *dequeue_forget(struct fuse_conn *fc,
  845. unsigned max,
  846. unsigned *countp)
  847. {
  848. struct fuse_forget_link *head = fc->forget_list_head.next;
  849. struct fuse_forget_link **newhead = &head;
  850. unsigned count;
  851. for (count = 0; *newhead != NULL && count < max; count++)
  852. newhead = &(*newhead)->next;
  853. fc->forget_list_head.next = *newhead;
  854. *newhead = NULL;
  855. if (fc->forget_list_head.next == NULL)
  856. fc->forget_list_tail = &fc->forget_list_head;
  857. if (countp != NULL)
  858. *countp = count;
  859. return head;
  860. }
  861. static int fuse_read_single_forget(struct fuse_conn *fc,
  862. struct fuse_copy_state *cs,
  863. size_t nbytes)
  864. __releases(fc->lock)
  865. {
  866. int err;
  867. struct fuse_forget_link *forget = dequeue_forget(fc, 1, NULL);
  868. struct fuse_forget_in arg = {
  869. .nlookup = forget->forget_one.nlookup,
  870. };
  871. struct fuse_in_header ih = {
  872. .opcode = FUSE_FORGET,
  873. .nodeid = forget->forget_one.nodeid,
  874. .unique = fuse_get_unique(fc),
  875. .len = sizeof(ih) + sizeof(arg),
  876. };
  877. spin_unlock(&fc->lock);
  878. kfree(forget);
  879. if (nbytes < ih.len)
  880. return -EINVAL;
  881. err = fuse_copy_one(cs, &ih, sizeof(ih));
  882. if (!err)
  883. err = fuse_copy_one(cs, &arg, sizeof(arg));
  884. fuse_copy_finish(cs);
  885. if (err)
  886. return err;
  887. return ih.len;
  888. }
  889. static int fuse_read_batch_forget(struct fuse_conn *fc,
  890. struct fuse_copy_state *cs, size_t nbytes)
  891. __releases(fc->lock)
  892. {
  893. int err;
  894. unsigned max_forgets;
  895. unsigned count;
  896. struct fuse_forget_link *head;
  897. struct fuse_batch_forget_in arg = { .count = 0 };
  898. struct fuse_in_header ih = {
  899. .opcode = FUSE_BATCH_FORGET,
  900. .unique = fuse_get_unique(fc),
  901. .len = sizeof(ih) + sizeof(arg),
  902. };
  903. if (nbytes < ih.len) {
  904. spin_unlock(&fc->lock);
  905. return -EINVAL;
  906. }
  907. max_forgets = (nbytes - ih.len) / sizeof(struct fuse_forget_one);
  908. head = dequeue_forget(fc, max_forgets, &count);
  909. spin_unlock(&fc->lock);
  910. arg.count = count;
  911. ih.len += count * sizeof(struct fuse_forget_one);
  912. err = fuse_copy_one(cs, &ih, sizeof(ih));
  913. if (!err)
  914. err = fuse_copy_one(cs, &arg, sizeof(arg));
  915. while (head) {
  916. struct fuse_forget_link *forget = head;
  917. if (!err) {
  918. err = fuse_copy_one(cs, &forget->forget_one,
  919. sizeof(forget->forget_one));
  920. }
  921. head = forget->next;
  922. kfree(forget);
  923. }
  924. fuse_copy_finish(cs);
  925. if (err)
  926. return err;
  927. return ih.len;
  928. }
  929. static int fuse_read_forget(struct fuse_conn *fc, struct fuse_copy_state *cs,
  930. size_t nbytes)
  931. __releases(fc->lock)
  932. {
  933. if (fc->minor < 16 || fc->forget_list_head.next->next == NULL)
  934. return fuse_read_single_forget(fc, cs, nbytes);
  935. else
  936. return fuse_read_batch_forget(fc, cs, nbytes);
  937. }
  938. /*
  939. * Read a single request into the userspace filesystem's buffer. This
  940. * function waits until a request is available, then removes it from
  941. * the pending list and copies request data to userspace buffer. If
  942. * no reply is needed (FORGET) or request has been aborted or there
  943. * was an error during the copying then it's finished by calling
  944. * request_end(). Otherwise add it to the processing list, and set
  945. * the 'sent' flag.
  946. */
  947. static ssize_t fuse_dev_do_read(struct fuse_conn *fc, struct file *file,
  948. struct fuse_copy_state *cs, size_t nbytes)
  949. {
  950. int err;
  951. struct fuse_req *req;
  952. struct fuse_in *in;
  953. unsigned reqsize;
  954. restart:
  955. spin_lock(&fc->lock);
  956. err = -EAGAIN;
  957. if ((file->f_flags & O_NONBLOCK) && fc->connected &&
  958. !request_pending(fc))
  959. goto err_unlock;
  960. request_wait(fc);
  961. err = -ENODEV;
  962. if (!fc->connected)
  963. goto err_unlock;
  964. err = -ERESTARTSYS;
  965. if (!request_pending(fc))
  966. goto err_unlock;
  967. if (!list_empty(&fc->interrupts)) {
  968. req = list_entry(fc->interrupts.next, struct fuse_req,
  969. intr_entry);
  970. return fuse_read_interrupt(fc, cs, nbytes, req);
  971. }
  972. if (forget_pending(fc)) {
  973. if (list_empty(&fc->pending) || fc->forget_batch-- > 0)
  974. return fuse_read_forget(fc, cs, nbytes);
  975. if (fc->forget_batch <= -8)
  976. fc->forget_batch = 16;
  977. }
  978. req = list_entry(fc->pending.next, struct fuse_req, list);
  979. req->state = FUSE_REQ_READING;
  980. list_move(&req->list, &fc->io);
  981. in = &req->in;
  982. reqsize = in->h.len;
  983. /* If request is too large, reply with an error and restart the read */
  984. if (nbytes < reqsize) {
  985. req->out.h.error = -EIO;
  986. /* SETXATTR is special, since it may contain too large data */
  987. if (in->h.opcode == FUSE_SETXATTR)
  988. req->out.h.error = -E2BIG;
  989. request_end(fc, req);
  990. goto restart;
  991. }
  992. spin_unlock(&fc->lock);
  993. cs->req = req;
  994. err = fuse_copy_one(cs, &in->h, sizeof(in->h));
  995. if (!err)
  996. err = fuse_copy_args(cs, in->numargs, in->argpages,
  997. (struct fuse_arg *) in->args, 0);
  998. fuse_copy_finish(cs);
  999. spin_lock(&fc->lock);
  1000. req->locked = 0;
  1001. if (req->aborted) {
  1002. request_end(fc, req);
  1003. return -ENODEV;
  1004. }
  1005. if (err) {
  1006. req->out.h.error = -EIO;
  1007. request_end(fc, req);
  1008. return err;
  1009. }
  1010. if (!req->isreply)
  1011. request_end(fc, req);
  1012. else {
  1013. req->state = FUSE_REQ_SENT;
  1014. list_move_tail(&req->list, &fc->processing);
  1015. if (req->interrupted)
  1016. queue_interrupt(fc, req);
  1017. spin_unlock(&fc->lock);
  1018. }
  1019. return reqsize;
  1020. err_unlock:
  1021. spin_unlock(&fc->lock);
  1022. return err;
  1023. }
  1024. static ssize_t fuse_dev_read(struct kiocb *iocb, const struct iovec *iov,
  1025. unsigned long nr_segs, loff_t pos)
  1026. {
  1027. struct fuse_copy_state cs;
  1028. struct file *file = iocb->ki_filp;
  1029. struct fuse_conn *fc = fuse_get_conn(file);
  1030. if (!fc)
  1031. return -EPERM;
  1032. fuse_copy_init(&cs, fc, 1, iov, nr_segs);
  1033. return fuse_dev_do_read(fc, file, &cs, iov_length(iov, nr_segs));
  1034. }
  1035. static int fuse_dev_pipe_buf_steal(struct pipe_inode_info *pipe,
  1036. struct pipe_buffer *buf)
  1037. {
  1038. return 1;
  1039. }
  1040. static const struct pipe_buf_operations fuse_dev_pipe_buf_ops = {
  1041. .can_merge = 0,
  1042. .map = generic_pipe_buf_map,
  1043. .unmap = generic_pipe_buf_unmap,
  1044. .confirm = generic_pipe_buf_confirm,
  1045. .release = generic_pipe_buf_release,
  1046. .steal = fuse_dev_pipe_buf_steal,
  1047. .get = generic_pipe_buf_get,
  1048. };
  1049. static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
  1050. struct pipe_inode_info *pipe,
  1051. size_t len, unsigned int flags)
  1052. {
  1053. int ret;
  1054. int page_nr = 0;
  1055. int do_wakeup = 0;
  1056. struct pipe_buffer *bufs;
  1057. struct fuse_copy_state cs;
  1058. struct fuse_conn *fc = fuse_get_conn(in);
  1059. if (!fc)
  1060. return -EPERM;
  1061. bufs = kmalloc(pipe->buffers * sizeof(struct pipe_buffer), GFP_KERNEL);
  1062. if (!bufs)
  1063. return -ENOMEM;
  1064. fuse_copy_init(&cs, fc, 1, NULL, 0);
  1065. cs.pipebufs = bufs;
  1066. cs.pipe = pipe;
  1067. ret = fuse_dev_do_read(fc, in, &cs, len);
  1068. if (ret < 0)
  1069. goto out;
  1070. ret = 0;
  1071. pipe_lock(pipe);
  1072. if (!pipe->readers) {
  1073. send_sig(SIGPIPE, current, 0);
  1074. if (!ret)
  1075. ret = -EPIPE;
  1076. goto out_unlock;
  1077. }
  1078. if (pipe->nrbufs + cs.nr_segs > pipe->buffers) {
  1079. ret = -EIO;
  1080. goto out_unlock;
  1081. }
  1082. while (page_nr < cs.nr_segs) {
  1083. int newbuf = (pipe->curbuf + pipe->nrbufs) & (pipe->buffers - 1);
  1084. struct pipe_buffer *buf = pipe->bufs + newbuf;
  1085. buf->page = bufs[page_nr].page;
  1086. buf->offset = bufs[page_nr].offset;
  1087. buf->len = bufs[page_nr].len;
  1088. buf->ops = &fuse_dev_pipe_buf_ops;
  1089. pipe->nrbufs++;
  1090. page_nr++;
  1091. ret += buf->len;
  1092. if (pipe->inode)
  1093. do_wakeup = 1;
  1094. }
  1095. out_unlock:
  1096. pipe_unlock(pipe);
  1097. if (do_wakeup) {
  1098. smp_mb();
  1099. if (waitqueue_active(&pipe->wait))
  1100. wake_up_interruptible(&pipe->wait);
  1101. kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
  1102. }
  1103. out:
  1104. for (; page_nr < cs.nr_segs; page_nr++)
  1105. page_cache_release(bufs[page_nr].page);
  1106. kfree(bufs);
  1107. return ret;
  1108. }
  1109. static int fuse_notify_poll(struct fuse_conn *fc, unsigned int size,
  1110. struct fuse_copy_state *cs)
  1111. {
  1112. struct fuse_notify_poll_wakeup_out outarg;
  1113. int err = -EINVAL;
  1114. if (size != sizeof(outarg))
  1115. goto err;
  1116. err = fuse_copy_one(cs, &outarg, sizeof(outarg));
  1117. if (err)
  1118. goto err;
  1119. fuse_copy_finish(cs);
  1120. return fuse_notify_poll_wakeup(fc, &outarg);
  1121. err:
  1122. fuse_copy_finish(cs);
  1123. return err;
  1124. }
  1125. static int fuse_notify_inval_inode(struct fuse_conn *fc, unsigned int size,
  1126. struct fuse_copy_state *cs)
  1127. {
  1128. struct fuse_notify_inval_inode_out outarg;
  1129. int err = -EINVAL;
  1130. if (size != sizeof(outarg))
  1131. goto err;
  1132. err = fuse_copy_one(cs, &outarg, sizeof(outarg));
  1133. if (err)
  1134. goto err;
  1135. fuse_copy_finish(cs);
  1136. down_read(&fc->killsb);
  1137. err = -ENOENT;
  1138. if (fc->sb) {
  1139. err = fuse_reverse_inval_inode(fc->sb, outarg.ino,
  1140. outarg.off, outarg.len);
  1141. }
  1142. up_read(&fc->killsb);
  1143. return err;
  1144. err:
  1145. fuse_copy_finish(cs);
  1146. return err;
  1147. }
  1148. static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size,
  1149. struct fuse_copy_state *cs)
  1150. {
  1151. struct fuse_notify_inval_entry_out outarg;
  1152. int err = -ENOMEM;
  1153. char *buf;
  1154. struct qstr name;
  1155. buf = kzalloc(FUSE_NAME_MAX + 1, GFP_KERNEL);
  1156. if (!buf)
  1157. goto err;
  1158. err = -EINVAL;
  1159. if (size < sizeof(outarg))
  1160. goto err;
  1161. err = fuse_copy_one(cs, &outarg, sizeof(outarg));
  1162. if (err)
  1163. goto err;
  1164. err = -ENAMETOOLONG;
  1165. if (outarg.namelen > FUSE_NAME_MAX)
  1166. goto err;
  1167. err = -EINVAL;
  1168. if (size != sizeof(outarg) + outarg.namelen + 1)
  1169. goto err;
  1170. name.name = buf;
  1171. name.len = outarg.namelen;
  1172. err = fuse_copy_one(cs, buf, outarg.namelen + 1);
  1173. if (err)
  1174. goto err;
  1175. fuse_copy_finish(cs);
  1176. buf[outarg.namelen] = 0;
  1177. name.hash = full_name_hash(name.name, name.len);
  1178. down_read(&fc->killsb);
  1179. err = -ENOENT;
  1180. if (fc->sb)
  1181. err = fuse_reverse_inval_entry(fc->sb, outarg.parent, &name);
  1182. up_read(&fc->killsb);
  1183. kfree(buf);
  1184. return err;
  1185. err:
  1186. kfree(buf);
  1187. fuse_copy_finish(cs);
  1188. return err;
  1189. }
  1190. static int fuse_notify_store(struct fuse_conn *fc, unsigned int size,
  1191. struct fuse_copy_state *cs)
  1192. {
  1193. struct fuse_notify_store_out outarg;
  1194. struct inode *inode;
  1195. struct address_space *mapping;
  1196. u64 nodeid;
  1197. int err;
  1198. pgoff_t index;
  1199. unsigned int offset;
  1200. unsigned int num;
  1201. loff_t file_size;
  1202. loff_t end;
  1203. err = -EINVAL;
  1204. if (size < sizeof(outarg))
  1205. goto out_finish;
  1206. err = fuse_copy_one(cs, &outarg, sizeof(outarg));
  1207. if (err)
  1208. goto out_finish;
  1209. err = -EINVAL;
  1210. if (size - sizeof(outarg) != outarg.size)
  1211. goto out_finish;
  1212. nodeid = outarg.nodeid;
  1213. down_read(&fc->killsb);
  1214. err = -ENOENT;
  1215. if (!fc->sb)
  1216. goto out_up_killsb;
  1217. inode = ilookup5(fc->sb, nodeid, fuse_inode_eq, &nodeid);
  1218. if (!inode)
  1219. goto out_up_killsb;
  1220. mapping = inode->i_mapping;
  1221. index = outarg.offset >> PAGE_CACHE_SHIFT;
  1222. offset = outarg.offset & ~PAGE_CACHE_MASK;
  1223. file_size = i_size_read(inode);
  1224. end = outarg.offset + outarg.size;
  1225. if (end > file_size) {
  1226. file_size = end;
  1227. fuse_write_update_size(inode, file_size);
  1228. }
  1229. num = outarg.size;
  1230. while (num) {
  1231. struct page *page;
  1232. unsigned int this_num;
  1233. err = -ENOMEM;
  1234. page = find_or_create_page(mapping, index,
  1235. mapping_gfp_mask(mapping));
  1236. if (!page)
  1237. goto out_iput;
  1238. this_num = min_t(unsigned, num, PAGE_CACHE_SIZE - offset);
  1239. err = fuse_copy_page(cs, &page, offset, this_num, 0);
  1240. if (!err && offset == 0 && (num != 0 || file_size == end))
  1241. SetPageUptodate(page);
  1242. unlock_page(page);
  1243. page_cache_release(page);
  1244. if (err)
  1245. goto out_iput;
  1246. num -= this_num;
  1247. offset = 0;
  1248. index++;
  1249. }
  1250. err = 0;
  1251. out_iput:
  1252. iput(inode);
  1253. out_up_killsb:
  1254. up_read(&fc->killsb);
  1255. out_finish:
  1256. fuse_copy_finish(cs);
  1257. return err;
  1258. }
  1259. static void fuse_retrieve_end(struct fuse_conn *fc, struct fuse_req *req)
  1260. {
  1261. release_pages(req->pages, req->num_pages, 0);
  1262. }
  1263. static int fuse_retrieve(struct fuse_conn *fc, struct inode *inode,
  1264. struct fuse_notify_retrieve_out *outarg)
  1265. {
  1266. int err;
  1267. struct address_space *mapping = inode->i_mapping;
  1268. struct fuse_req *req;
  1269. pgoff_t index;
  1270. loff_t file_size;
  1271. unsigned int num;
  1272. unsigned int offset;
  1273. size_t total_len = 0;
  1274. req = fuse_get_req(fc);
  1275. if (IS_ERR(req))
  1276. return PTR_ERR(req);
  1277. offset = outarg->offset & ~PAGE_CACHE_MASK;
  1278. req->in.h.opcode = FUSE_NOTIFY_REPLY;
  1279. req->in.h.nodeid = outarg->nodeid;
  1280. req->in.numargs = 2;
  1281. req->in.argpages = 1;
  1282. req->page_offset = offset;
  1283. req->end = fuse_retrieve_end;
  1284. index = outarg->offset >> PAGE_CACHE_SHIFT;
  1285. file_size = i_size_read(inode);
  1286. num = outarg->size;
  1287. if (outarg->offset > file_size)
  1288. num = 0;
  1289. else if (outarg->offset + num > file_size)
  1290. num = file_size - outarg->offset;
  1291. while (num) {
  1292. struct page *page;
  1293. unsigned int this_num;
  1294. page = find_get_page(mapping, index);
  1295. if (!page)
  1296. break;
  1297. this_num = min_t(unsigned, num, PAGE_CACHE_SIZE - offset);
  1298. req->pages[req->num_pages] = page;
  1299. req->num_pages++;
  1300. num -= this_num;
  1301. total_len += this_num;
  1302. }
  1303. req->misc.retrieve_in.offset = outarg->offset;
  1304. req->misc.retrieve_in.size = total_len;
  1305. req->in.args[0].size = sizeof(req->misc.retrieve_in);
  1306. req->in.args[0].value = &req->misc.retrieve_in;
  1307. req->in.args[1].size = total_len;
  1308. err = fuse_request_send_notify_reply(fc, req, outarg->notify_unique);
  1309. if (err)
  1310. fuse_retrieve_end(fc, req);
  1311. return err;
  1312. }
  1313. static int fuse_notify_retrieve(struct fuse_conn *fc, unsigned int size,
  1314. struct fuse_copy_state *cs)
  1315. {
  1316. struct fuse_notify_retrieve_out outarg;
  1317. struct inode *inode;
  1318. int err;
  1319. err = -EINVAL;
  1320. if (size != sizeof(outarg))
  1321. goto copy_finish;
  1322. err = fuse_copy_one(cs, &outarg, sizeof(outarg));
  1323. if (err)
  1324. goto copy_finish;
  1325. fuse_copy_finish(cs);
  1326. down_read(&fc->killsb);
  1327. err = -ENOENT;
  1328. if (fc->sb) {
  1329. u64 nodeid = outarg.nodeid;
  1330. inode = ilookup5(fc->sb, nodeid, fuse_inode_eq, &nodeid);
  1331. if (inode) {
  1332. err = fuse_retrieve(fc, inode, &outarg);
  1333. iput(inode);
  1334. }
  1335. }
  1336. up_read(&fc->killsb);
  1337. return err;
  1338. copy_finish:
  1339. fuse_copy_finish(cs);
  1340. return err;
  1341. }
  1342. static int fuse_notify(struct fuse_conn *fc, enum fuse_notify_code code,
  1343. unsigned int size, struct fuse_copy_state *cs)
  1344. {
  1345. switch (code) {
  1346. case FUSE_NOTIFY_POLL:
  1347. return fuse_notify_poll(fc, size, cs);
  1348. case FUSE_NOTIFY_INVAL_INODE:
  1349. return fuse_notify_inval_inode(fc, size, cs);
  1350. case FUSE_NOTIFY_INVAL_ENTRY:
  1351. return fuse_notify_inval_entry(fc, size, cs);
  1352. case FUSE_NOTIFY_STORE:
  1353. return fuse_notify_store(fc, size, cs);
  1354. case FUSE_NOTIFY_RETRIEVE:
  1355. return fuse_notify_retrieve(fc, size, cs);
  1356. default:
  1357. fuse_copy_finish(cs);
  1358. return -EINVAL;
  1359. }
  1360. }
  1361. /* Look up request on processing list by unique ID */
  1362. static struct fuse_req *request_find(struct fuse_conn *fc, u64 unique)
  1363. {
  1364. struct list_head *entry;
  1365. list_for_each(entry, &fc->processing) {
  1366. struct fuse_req *req;
  1367. req = list_entry(entry, struct fuse_req, list);
  1368. if (req->in.h.unique == unique || req->intr_unique == unique)
  1369. return req;
  1370. }
  1371. return NULL;
  1372. }
  1373. static int copy_out_args(struct fuse_copy_state *cs, struct fuse_out *out,
  1374. unsigned nbytes)
  1375. {
  1376. unsigned reqsize = sizeof(struct fuse_out_header);
  1377. if (out->h.error)
  1378. return nbytes != reqsize ? -EINVAL : 0;
  1379. reqsize += len_args(out->numargs, out->args);
  1380. if (reqsize < nbytes || (reqsize > nbytes && !out->argvar))
  1381. return -EINVAL;
  1382. else if (reqsize > nbytes) {
  1383. struct fuse_arg *lastarg = &out->args[out->numargs-1];
  1384. unsigned diffsize = reqsize - nbytes;
  1385. if (diffsize > lastarg->size)
  1386. return -EINVAL;
  1387. lastarg->size -= diffsize;
  1388. }
  1389. return fuse_copy_args(cs, out->numargs, out->argpages, out->args,
  1390. out->page_zeroing);
  1391. }
  1392. /*
  1393. * Write a single reply to a request. First the header is copied from
  1394. * the write buffer. The request is then searched on the processing
  1395. * list by the unique ID found in the header. If found, then remove
  1396. * it from the list and copy the rest of the buffer to the request.
  1397. * The request is finished by calling request_end()
  1398. */
  1399. static ssize_t fuse_dev_do_write(struct fuse_conn *fc,
  1400. struct fuse_copy_state *cs, size_t nbytes)
  1401. {
  1402. int err;
  1403. struct fuse_req *req;
  1404. struct fuse_out_header oh;
  1405. if (nbytes < sizeof(struct fuse_out_header))
  1406. return -EINVAL;
  1407. err = fuse_copy_one(cs, &oh, sizeof(oh));
  1408. if (err)
  1409. goto err_finish;
  1410. err = -EINVAL;
  1411. if (oh.len != nbytes)
  1412. goto err_finish;
  1413. /*
  1414. * Zero oh.unique indicates unsolicited notification message
  1415. * and error contains notification code.
  1416. */
  1417. if (!oh.unique) {
  1418. err = fuse_notify(fc, oh.error, nbytes - sizeof(oh), cs);
  1419. return err ? err : nbytes;
  1420. }
  1421. err = -EINVAL;
  1422. if (oh.error <= -1000 || oh.error > 0)
  1423. goto err_finish;
  1424. spin_lock(&fc->lock);
  1425. err = -ENOENT;
  1426. if (!fc->connected)
  1427. goto err_unlock;
  1428. req = request_find(fc, oh.unique);
  1429. if (!req)
  1430. goto err_unlock;
  1431. if (req->aborted) {
  1432. spin_unlock(&fc->lock);
  1433. fuse_copy_finish(cs);
  1434. spin_lock(&fc->lock);
  1435. request_end(fc, req);
  1436. return -ENOENT;
  1437. }
  1438. /* Is it an interrupt reply? */
  1439. if (req->intr_unique == oh.unique) {
  1440. err = -EINVAL;
  1441. if (nbytes != sizeof(struct fuse_out_header))
  1442. goto err_unlock;
  1443. if (oh.error == -ENOSYS)
  1444. fc->no_interrupt = 1;
  1445. else if (oh.error == -EAGAIN)
  1446. queue_interrupt(fc, req);
  1447. spin_unlock(&fc->lock);
  1448. fuse_copy_finish(cs);
  1449. return nbytes;
  1450. }
  1451. req->state = FUSE_REQ_WRITING;
  1452. list_move(&req->list, &fc->io);
  1453. req->out.h = oh;
  1454. req->locked = 1;
  1455. cs->req = req;
  1456. if (!req->out.page_replace)
  1457. cs->move_pages = 0;
  1458. spin_unlock(&fc->lock);
  1459. err = copy_out_args(cs, &req->out, nbytes);
  1460. fuse_copy_finish(cs);
  1461. spin_lock(&fc->lock);
  1462. req->locked = 0;
  1463. if (!err) {
  1464. if (req->aborted)
  1465. err = -ENOENT;
  1466. } else if (!req->aborted)
  1467. req->out.h.error = -EIO;
  1468. request_end(fc, req);
  1469. return err ? err : nbytes;
  1470. err_unlock:
  1471. spin_unlock(&fc->lock);
  1472. err_finish:
  1473. fuse_copy_finish(cs);
  1474. return err;
  1475. }
  1476. static ssize_t fuse_dev_write(struct kiocb *iocb, const struct iovec *iov,
  1477. unsigned long nr_segs, loff_t pos)
  1478. {
  1479. struct fuse_copy_state cs;
  1480. struct fuse_conn *fc = fuse_get_conn(iocb->ki_filp);
  1481. if (!fc)
  1482. return -EPERM;
  1483. fuse_copy_init(&cs, fc, 0, iov, nr_segs);
  1484. return fuse_dev_do_write(fc, &cs, iov_length(iov, nr_segs));
  1485. }
  1486. static ssize_t fuse_dev_splice_write(struct pipe_inode_info *pipe,
  1487. struct file *out, loff_t *ppos,
  1488. size_t len, unsigned int flags)
  1489. {
  1490. unsigned nbuf;
  1491. unsigned idx;
  1492. struct pipe_buffer *bufs;
  1493. struct fuse_copy_state cs;
  1494. struct fuse_conn *fc;
  1495. size_t rem;
  1496. ssize_t ret;
  1497. fc = fuse_get_conn(out);
  1498. if (!fc)
  1499. return -EPERM;
  1500. bufs = kmalloc(pipe->buffers * sizeof(struct pipe_buffer), GFP_KERNEL);
  1501. if (!bufs)
  1502. return -ENOMEM;
  1503. pipe_lock(pipe);
  1504. nbuf = 0;
  1505. rem = 0;
  1506. for (idx = 0; idx < pipe->nrbufs && rem < len; idx++)
  1507. rem += pipe->bufs[(pipe->curbuf + idx) & (pipe->buffers - 1)].len;
  1508. ret = -EINVAL;
  1509. if (rem < len) {
  1510. pipe_unlock(pipe);
  1511. goto out;
  1512. }
  1513. rem = len;
  1514. while (rem) {
  1515. struct pipe_buffer *ibuf;
  1516. struct pipe_buffer *obuf;
  1517. BUG_ON(nbuf >= pipe->buffers);
  1518. BUG_ON(!pipe->nrbufs);
  1519. ibuf = &pipe->bufs[pipe->curbuf];
  1520. obuf = &bufs[nbuf];
  1521. if (rem >= ibuf->len) {
  1522. *obuf = *ibuf;
  1523. ibuf->ops = NULL;
  1524. pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
  1525. pipe->nrbufs--;
  1526. } else {
  1527. ibuf->ops->get(pipe, ibuf);
  1528. *obuf = *ibuf;
  1529. obuf->flags &= ~PIPE_BUF_FLAG_GIFT;
  1530. obuf->len = rem;
  1531. ibuf->offset += obuf->len;
  1532. ibuf->len -= obuf->len;
  1533. }
  1534. nbuf++;
  1535. rem -= obuf->len;
  1536. }
  1537. pipe_unlock(pipe);
  1538. fuse_copy_init(&cs, fc, 0, NULL, nbuf);
  1539. cs.pipebufs = bufs;
  1540. cs.pipe = pipe;
  1541. if (flags & SPLICE_F_MOVE)
  1542. cs.move_pages = 1;
  1543. ret = fuse_dev_do_write(fc, &cs, len);
  1544. for (idx = 0; idx < nbuf; idx++) {
  1545. struct pipe_buffer *buf = &bufs[idx];
  1546. buf->ops->release(pipe, buf);
  1547. }
  1548. out:
  1549. kfree(bufs);
  1550. return ret;
  1551. }
  1552. static unsigned fuse_dev_poll(struct file *file, poll_table *wait)
  1553. {
  1554. unsigned mask = POLLOUT | POLLWRNORM;
  1555. struct fuse_conn *fc = fuse_get_conn(file);
  1556. if (!fc)
  1557. return POLLERR;
  1558. poll_wait(file, &fc->waitq, wait);
  1559. spin_lock(&fc->lock);
  1560. if (!fc->connected)
  1561. mask = POLLERR;
  1562. else if (request_pending(fc))
  1563. mask |= POLLIN | POLLRDNORM;
  1564. spin_unlock(&fc->lock);
  1565. return mask;
  1566. }
  1567. /*
  1568. * Abort all requests on the given list (pending or processing)
  1569. *
  1570. * This function releases and reacquires fc->lock
  1571. */
  1572. static void end_requests(struct fuse_conn *fc, struct list_head *head)
  1573. __releases(fc->lock)
  1574. __acquires(fc->lock)
  1575. {
  1576. while (!list_empty(head)) {
  1577. struct fuse_req *req;
  1578. req = list_entry(head->next, struct fuse_req, list);
  1579. req->out.h.error = -ECONNABORTED;
  1580. request_end(fc, req);
  1581. spin_lock(&fc->lock);
  1582. }
  1583. }
  1584. /*
  1585. * Abort requests under I/O
  1586. *
  1587. * The requests are set to aborted and finished, and the request
  1588. * waiter is woken up. This will make request_wait_answer() wait
  1589. * until the request is unlocked and then return.
  1590. *
  1591. * If the request is asynchronous, then the end function needs to be
  1592. * called after waiting for the request to be unlocked (if it was
  1593. * locked).
  1594. */
  1595. static void end_io_requests(struct fuse_conn *fc)
  1596. __releases(fc->lock)
  1597. __acquires(fc->lock)
  1598. {
  1599. while (!list_empty(&fc->io)) {
  1600. struct fuse_req *req =
  1601. list_entry(fc->io.next, struct fuse_req, list);
  1602. void (*end) (struct fuse_conn *, struct fuse_req *) = req->end;
  1603. req->aborted = 1;
  1604. req->out.h.error = -ECONNABORTED;
  1605. req->state = FUSE_REQ_FINISHED;
  1606. list_del_init(&req->list);
  1607. wake_up(&req->waitq);
  1608. if (end) {
  1609. req->end = NULL;
  1610. __fuse_get_request(req);
  1611. spin_unlock(&fc->lock);
  1612. wait_event(req->waitq, !req->locked);
  1613. end(fc, req);
  1614. fuse_put_request(fc, req);
  1615. spin_lock(&fc->lock);
  1616. }
  1617. }
  1618. }
  1619. static void end_queued_requests(struct fuse_conn *fc)
  1620. __releases(fc->lock)
  1621. __acquires(fc->lock)
  1622. {
  1623. fc->max_background = UINT_MAX;
  1624. flush_bg_queue(fc);
  1625. end_requests(fc, &fc->pending);
  1626. end_requests(fc, &fc->processing);
  1627. while (forget_pending(fc))
  1628. kfree(dequeue_forget(fc, 1, NULL));
  1629. }
  1630. static void end_polls(struct fuse_conn *fc)
  1631. {
  1632. struct rb_node *p;
  1633. p = rb_first(&fc->polled_files);
  1634. while (p) {
  1635. struct fuse_file *ff;
  1636. ff = rb_entry(p, struct fuse_file, polled_node);
  1637. wake_up_interruptible_all(&ff->poll_wait);
  1638. p = rb_next(p);
  1639. }
  1640. }
  1641. /*
  1642. * Abort all requests.
  1643. *
  1644. * Emergency exit in case of a malicious or accidental deadlock, or
  1645. * just a hung filesystem.
  1646. *
  1647. * The same effect is usually achievable through killing the
  1648. * filesystem daemon and all users of the filesystem. The exception
  1649. * is the combination of an asynchronous request and the tricky
  1650. * deadlock (see Documentation/filesystems/fuse.txt).
  1651. *
  1652. * During the aborting, progression of requests from the pending and
  1653. * processing lists onto the io list, and progression of new requests
  1654. * onto the pending list is prevented by req->connected being false.
  1655. *
  1656. * Progression of requests under I/O to the processing list is
  1657. * prevented by the req->aborted flag being true for these requests.
  1658. * For this reason requests on the io list must be aborted first.
  1659. */
  1660. void fuse_abort_conn(struct fuse_conn *fc)
  1661. {
  1662. spin_lock(&fc->lock);
  1663. if (fc->connected) {
  1664. fc->connected = 0;
  1665. fc->blocked = 0;
  1666. end_io_requests(fc);
  1667. end_queued_requests(fc);
  1668. end_polls(fc);
  1669. wake_up_all(&fc->waitq);
  1670. wake_up_all(&fc->blocked_waitq);
  1671. kill_fasync(&fc->fasync, SIGIO, POLL_IN);
  1672. }
  1673. spin_unlock(&fc->lock);
  1674. }
  1675. EXPORT_SYMBOL_GPL(fuse_abort_conn);
  1676. int fuse_dev_release(struct inode *inode, struct file *file)
  1677. {
  1678. struct fuse_conn *fc = fuse_get_conn(file);
  1679. if (fc) {
  1680. spin_lock(&fc->lock);
  1681. fc->connected = 0;
  1682. fc->blocked = 0;
  1683. end_queued_requests(fc);
  1684. end_polls(fc);
  1685. wake_up_all(&fc->blocked_waitq);
  1686. spin_unlock(&fc->lock);
  1687. fuse_conn_put(fc);
  1688. }
  1689. return 0;
  1690. }
  1691. EXPORT_SYMBOL_GPL(fuse_dev_release);
  1692. static int fuse_dev_fasync(int fd, struct file *file, int on)
  1693. {
  1694. struct fuse_conn *fc = fuse_get_conn(file);
  1695. if (!fc)
  1696. return -EPERM;
  1697. /* No locking - fasync_helper does its own locking */
  1698. return fasync_helper(fd, file, on, &fc->fasync);
  1699. }
  1700. const struct file_operations fuse_dev_operations = {
  1701. .owner = THIS_MODULE,
  1702. .llseek = no_llseek,
  1703. .read = do_sync_read,
  1704. .aio_read = fuse_dev_read,
  1705. .splice_read = fuse_dev_splice_read,
  1706. .write = do_sync_write,
  1707. .aio_write = fuse_dev_write,
  1708. .splice_write = fuse_dev_splice_write,
  1709. .poll = fuse_dev_poll,
  1710. .release = fuse_dev_release,
  1711. .fasync = fuse_dev_fasync,
  1712. };
  1713. EXPORT_SYMBOL_GPL(fuse_dev_operations);
  1714. static struct miscdevice fuse_miscdevice = {
  1715. .minor = FUSE_MINOR,
  1716. .name = "fuse",
  1717. .fops = &fuse_dev_operations,
  1718. };
  1719. int __init fuse_dev_init(void)
  1720. {
  1721. int err = -ENOMEM;
  1722. fuse_req_cachep = kmem_cache_create("fuse_request",
  1723. sizeof(struct fuse_req),
  1724. 0, 0, NULL);
  1725. if (!fuse_req_cachep)
  1726. goto out;
  1727. err = misc_register(&fuse_miscdevice);
  1728. if (err)
  1729. goto out_cache_clean;
  1730. return 0;
  1731. out_cache_clean:
  1732. kmem_cache_destroy(fuse_req_cachep);
  1733. out:
  1734. return err;
  1735. }
  1736. void fuse_dev_cleanup(void)
  1737. {
  1738. misc_deregister(&fuse_miscdevice);
  1739. kmem_cache_destroy(fuse_req_cachep);
  1740. }