relay.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366
  1. /*
  2. * Public API and common code for kernel->userspace relay file support.
  3. *
  4. * See Documentation/filesystems/relay.txt for an overview.
  5. *
  6. * Copyright (C) 2002-2005 - Tom Zanussi (zanussi@us.ibm.com), IBM Corp
  7. * Copyright (C) 1999-2005 - Karim Yaghmour (karim@opersys.com)
  8. *
  9. * Moved to kernel/relay.c by Paul Mundt, 2006.
  10. * November 2006 - CPU hotplug support by Mathieu Desnoyers
  11. * (mathieu.desnoyers@polymtl.ca)
  12. *
  13. * This file is released under the GPL.
  14. */
  15. #include <linux/errno.h>
  16. #include <linux/stddef.h>
  17. #include <linux/slab.h>
  18. #include <linux/module.h>
  19. #include <linux/string.h>
  20. #include <linux/relay.h>
  21. #include <linux/vmalloc.h>
  22. #include <linux/mm.h>
  23. #include <linux/cpu.h>
  24. #include <linux/splice.h>
  25. /* list of open channels, for cpu hotplug */
  26. static DEFINE_MUTEX(relay_channels_mutex);
  27. static LIST_HEAD(relay_channels);
  28. /*
  29. * close() vm_op implementation for relay file mapping.
  30. */
  31. static void relay_file_mmap_close(struct vm_area_struct *vma)
  32. {
  33. struct rchan_buf *buf = vma->vm_private_data;
  34. buf->chan->cb->buf_unmapped(buf, vma->vm_file);
  35. }
  36. /*
  37. * fault() vm_op implementation for relay file mapping.
  38. */
  39. static int relay_buf_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
  40. {
  41. struct page *page;
  42. struct rchan_buf *buf = vma->vm_private_data;
  43. pgoff_t pgoff = vmf->pgoff;
  44. if (!buf)
  45. return VM_FAULT_OOM;
  46. page = vmalloc_to_page(buf->start + (pgoff << PAGE_SHIFT));
  47. if (!page)
  48. return VM_FAULT_SIGBUS;
  49. get_page(page);
  50. vmf->page = page;
  51. return 0;
  52. }
  53. /*
  54. * vm_ops for relay file mappings.
  55. */
  56. static const struct vm_operations_struct relay_file_mmap_ops = {
  57. .fault = relay_buf_fault,
  58. .close = relay_file_mmap_close,
  59. };
  60. /*
  61. * allocate an array of pointers of struct page
  62. */
  63. static struct page **relay_alloc_page_array(unsigned int n_pages)
  64. {
  65. const size_t pa_size = n_pages * sizeof(struct page *);
  66. if (pa_size > PAGE_SIZE)
  67. return vzalloc(pa_size);
  68. return kzalloc(pa_size, GFP_KERNEL);
  69. }
  70. /*
  71. * free an array of pointers of struct page
  72. */
  73. static void relay_free_page_array(struct page **array)
  74. {
  75. if (is_vmalloc_addr(array))
  76. vfree(array);
  77. else
  78. kfree(array);
  79. }
  80. /**
  81. * relay_mmap_buf: - mmap channel buffer to process address space
  82. * @buf: relay channel buffer
  83. * @vma: vm_area_struct describing memory to be mapped
  84. *
  85. * Returns 0 if ok, negative on error
  86. *
  87. * Caller should already have grabbed mmap_sem.
  88. */
  89. static int relay_mmap_buf(struct rchan_buf *buf, struct vm_area_struct *vma)
  90. {
  91. unsigned long length = vma->vm_end - vma->vm_start;
  92. struct file *filp = vma->vm_file;
  93. if (!buf)
  94. return -EBADF;
  95. if (length != (unsigned long)buf->chan->alloc_size)
  96. return -EINVAL;
  97. vma->vm_ops = &relay_file_mmap_ops;
  98. vma->vm_flags |= VM_DONTEXPAND;
  99. vma->vm_private_data = buf;
  100. buf->chan->cb->buf_mapped(buf, filp);
  101. return 0;
  102. }
  103. /**
  104. * relay_alloc_buf - allocate a channel buffer
  105. * @buf: the buffer struct
  106. * @size: total size of the buffer
  107. *
  108. * Returns a pointer to the resulting buffer, %NULL if unsuccessful. The
  109. * passed in size will get page aligned, if it isn't already.
  110. */
  111. static void *relay_alloc_buf(struct rchan_buf *buf, size_t *size)
  112. {
  113. void *mem;
  114. unsigned int i, j, n_pages;
  115. *size = PAGE_ALIGN(*size);
  116. n_pages = *size >> PAGE_SHIFT;
  117. buf->page_array = relay_alloc_page_array(n_pages);
  118. if (!buf->page_array)
  119. return NULL;
  120. for (i = 0; i < n_pages; i++) {
  121. buf->page_array[i] = alloc_page(GFP_KERNEL);
  122. if (unlikely(!buf->page_array[i]))
  123. goto depopulate;
  124. set_page_private(buf->page_array[i], (unsigned long)buf);
  125. }
  126. mem = vmap(buf->page_array, n_pages, VM_MAP, PAGE_KERNEL);
  127. if (!mem)
  128. goto depopulate;
  129. memset(mem, 0, *size);
  130. buf->page_count = n_pages;
  131. return mem;
  132. depopulate:
  133. for (j = 0; j < i; j++)
  134. __free_page(buf->page_array[j]);
  135. relay_free_page_array(buf->page_array);
  136. return NULL;
  137. }
  138. /**
  139. * relay_create_buf - allocate and initialize a channel buffer
  140. * @chan: the relay channel
  141. *
  142. * Returns channel buffer if successful, %NULL otherwise.
  143. */
  144. static struct rchan_buf *relay_create_buf(struct rchan *chan)
  145. {
  146. struct rchan_buf *buf;
  147. if (chan->n_subbufs > UINT_MAX / sizeof(size_t *))
  148. return NULL;
  149. buf = kzalloc(sizeof(struct rchan_buf), GFP_KERNEL);
  150. if (!buf)
  151. return NULL;
  152. buf->padding = kmalloc(chan->n_subbufs * sizeof(size_t *), GFP_KERNEL);
  153. if (!buf->padding)
  154. goto free_buf;
  155. buf->start = relay_alloc_buf(buf, &chan->alloc_size);
  156. if (!buf->start)
  157. goto free_buf;
  158. buf->chan = chan;
  159. kref_get(&buf->chan->kref);
  160. return buf;
  161. free_buf:
  162. kfree(buf->padding);
  163. kfree(buf);
  164. return NULL;
  165. }
  166. /**
  167. * relay_destroy_channel - free the channel struct
  168. * @kref: target kernel reference that contains the relay channel
  169. *
  170. * Should only be called from kref_put().
  171. */
  172. static void relay_destroy_channel(struct kref *kref)
  173. {
  174. struct rchan *chan = container_of(kref, struct rchan, kref);
  175. kfree(chan);
  176. }
  177. /**
  178. * relay_destroy_buf - destroy an rchan_buf struct and associated buffer
  179. * @buf: the buffer struct
  180. */
  181. static void relay_destroy_buf(struct rchan_buf *buf)
  182. {
  183. struct rchan *chan = buf->chan;
  184. unsigned int i;
  185. if (likely(buf->start)) {
  186. vunmap(buf->start);
  187. for (i = 0; i < buf->page_count; i++)
  188. __free_page(buf->page_array[i]);
  189. relay_free_page_array(buf->page_array);
  190. }
  191. chan->buf[buf->cpu] = NULL;
  192. kfree(buf->padding);
  193. kfree(buf);
  194. kref_put(&chan->kref, relay_destroy_channel);
  195. }
  196. /**
  197. * relay_remove_buf - remove a channel buffer
  198. * @kref: target kernel reference that contains the relay buffer
  199. *
  200. * Removes the file from the fileystem, which also frees the
  201. * rchan_buf_struct and the channel buffer. Should only be called from
  202. * kref_put().
  203. */
  204. static void relay_remove_buf(struct kref *kref)
  205. {
  206. struct rchan_buf *buf = container_of(kref, struct rchan_buf, kref);
  207. buf->chan->cb->remove_buf_file(buf->dentry);
  208. relay_destroy_buf(buf);
  209. }
  210. /**
  211. * relay_buf_empty - boolean, is the channel buffer empty?
  212. * @buf: channel buffer
  213. *
  214. * Returns 1 if the buffer is empty, 0 otherwise.
  215. */
  216. static int relay_buf_empty(struct rchan_buf *buf)
  217. {
  218. return (buf->subbufs_produced - buf->subbufs_consumed) ? 0 : 1;
  219. }
  220. /**
  221. * relay_buf_full - boolean, is the channel buffer full?
  222. * @buf: channel buffer
  223. *
  224. * Returns 1 if the buffer is full, 0 otherwise.
  225. */
  226. int relay_buf_full(struct rchan_buf *buf)
  227. {
  228. size_t ready = buf->subbufs_produced - buf->subbufs_consumed;
  229. return (ready >= buf->chan->n_subbufs) ? 1 : 0;
  230. }
  231. EXPORT_SYMBOL_GPL(relay_buf_full);
  232. /*
  233. * High-level relay kernel API and associated functions.
  234. */
  235. /*
  236. * rchan_callback implementations defining default channel behavior. Used
  237. * in place of corresponding NULL values in client callback struct.
  238. */
  239. /*
  240. * subbuf_start() default callback. Does nothing.
  241. */
  242. static int subbuf_start_default_callback (struct rchan_buf *buf,
  243. void *subbuf,
  244. void *prev_subbuf,
  245. size_t prev_padding)
  246. {
  247. if (relay_buf_full(buf))
  248. return 0;
  249. return 1;
  250. }
  251. /*
  252. * buf_mapped() default callback. Does nothing.
  253. */
  254. static void buf_mapped_default_callback(struct rchan_buf *buf,
  255. struct file *filp)
  256. {
  257. }
  258. /*
  259. * buf_unmapped() default callback. Does nothing.
  260. */
  261. static void buf_unmapped_default_callback(struct rchan_buf *buf,
  262. struct file *filp)
  263. {
  264. }
  265. /*
  266. * create_buf_file_create() default callback. Does nothing.
  267. */
  268. static struct dentry *create_buf_file_default_callback(const char *filename,
  269. struct dentry *parent,
  270. int mode,
  271. struct rchan_buf *buf,
  272. int *is_global)
  273. {
  274. return NULL;
  275. }
  276. /*
  277. * remove_buf_file() default callback. Does nothing.
  278. */
  279. static int remove_buf_file_default_callback(struct dentry *dentry)
  280. {
  281. return -EINVAL;
  282. }
  283. /* relay channel default callbacks */
  284. static struct rchan_callbacks default_channel_callbacks = {
  285. .subbuf_start = subbuf_start_default_callback,
  286. .buf_mapped = buf_mapped_default_callback,
  287. .buf_unmapped = buf_unmapped_default_callback,
  288. .create_buf_file = create_buf_file_default_callback,
  289. .remove_buf_file = remove_buf_file_default_callback,
  290. };
  291. /**
  292. * wakeup_readers - wake up readers waiting on a channel
  293. * @data: contains the channel buffer
  294. *
  295. * This is the timer function used to defer reader waking.
  296. */
  297. static void wakeup_readers(unsigned long data)
  298. {
  299. struct rchan_buf *buf = (struct rchan_buf *)data;
  300. wake_up_interruptible(&buf->read_wait);
  301. }
  302. /**
  303. * __relay_reset - reset a channel buffer
  304. * @buf: the channel buffer
  305. * @init: 1 if this is a first-time initialization
  306. *
  307. * See relay_reset() for description of effect.
  308. */
  309. static void __relay_reset(struct rchan_buf *buf, unsigned int init)
  310. {
  311. size_t i;
  312. if (init) {
  313. init_waitqueue_head(&buf->read_wait);
  314. kref_init(&buf->kref);
  315. setup_timer(&buf->timer, wakeup_readers, (unsigned long)buf);
  316. } else
  317. del_timer_sync(&buf->timer);
  318. buf->subbufs_produced = 0;
  319. buf->subbufs_consumed = 0;
  320. buf->bytes_consumed = 0;
  321. buf->finalized = 0;
  322. buf->data = buf->start;
  323. buf->offset = 0;
  324. for (i = 0; i < buf->chan->n_subbufs; i++)
  325. buf->padding[i] = 0;
  326. buf->chan->cb->subbuf_start(buf, buf->data, NULL, 0);
  327. }
  328. /**
  329. * relay_reset - reset the channel
  330. * @chan: the channel
  331. *
  332. * This has the effect of erasing all data from all channel buffers
  333. * and restarting the channel in its initial state. The buffers
  334. * are not freed, so any mappings are still in effect.
  335. *
  336. * NOTE. Care should be taken that the channel isn't actually
  337. * being used by anything when this call is made.
  338. */
  339. void relay_reset(struct rchan *chan)
  340. {
  341. unsigned int i;
  342. if (!chan)
  343. return;
  344. if (chan->is_global && chan->buf[0]) {
  345. __relay_reset(chan->buf[0], 0);
  346. return;
  347. }
  348. mutex_lock(&relay_channels_mutex);
  349. for_each_possible_cpu(i)
  350. if (chan->buf[i])
  351. __relay_reset(chan->buf[i], 0);
  352. mutex_unlock(&relay_channels_mutex);
  353. }
  354. EXPORT_SYMBOL_GPL(relay_reset);
  355. static inline void relay_set_buf_dentry(struct rchan_buf *buf,
  356. struct dentry *dentry)
  357. {
  358. buf->dentry = dentry;
  359. buf->dentry->d_inode->i_size = buf->early_bytes;
  360. }
  361. static struct dentry *relay_create_buf_file(struct rchan *chan,
  362. struct rchan_buf *buf,
  363. unsigned int cpu)
  364. {
  365. struct dentry *dentry;
  366. char *tmpname;
  367. tmpname = kzalloc(NAME_MAX + 1, GFP_KERNEL);
  368. if (!tmpname)
  369. return NULL;
  370. snprintf(tmpname, NAME_MAX, "%s%d", chan->base_filename, cpu);
  371. /* Create file in fs */
  372. dentry = chan->cb->create_buf_file(tmpname, chan->parent,
  373. S_IRUSR, buf,
  374. &chan->is_global);
  375. kfree(tmpname);
  376. return dentry;
  377. }
  378. /*
  379. * relay_open_buf - create a new relay channel buffer
  380. *
  381. * used by relay_open() and CPU hotplug.
  382. */
  383. static struct rchan_buf *relay_open_buf(struct rchan *chan, unsigned int cpu)
  384. {
  385. struct rchan_buf *buf = NULL;
  386. struct dentry *dentry;
  387. if (chan->is_global)
  388. return chan->buf[0];
  389. buf = relay_create_buf(chan);
  390. if (!buf)
  391. return NULL;
  392. if (chan->has_base_filename) {
  393. dentry = relay_create_buf_file(chan, buf, cpu);
  394. if (!dentry)
  395. goto free_buf;
  396. relay_set_buf_dentry(buf, dentry);
  397. }
  398. buf->cpu = cpu;
  399. __relay_reset(buf, 1);
  400. if(chan->is_global) {
  401. chan->buf[0] = buf;
  402. buf->cpu = 0;
  403. }
  404. return buf;
  405. free_buf:
  406. relay_destroy_buf(buf);
  407. return NULL;
  408. }
  409. /**
  410. * relay_close_buf - close a channel buffer
  411. * @buf: channel buffer
  412. *
  413. * Marks the buffer finalized and restores the default callbacks.
  414. * The channel buffer and channel buffer data structure are then freed
  415. * automatically when the last reference is given up.
  416. */
  417. static void relay_close_buf(struct rchan_buf *buf)
  418. {
  419. buf->finalized = 1;
  420. del_timer_sync(&buf->timer);
  421. kref_put(&buf->kref, relay_remove_buf);
  422. }
  423. static void setup_callbacks(struct rchan *chan,
  424. struct rchan_callbacks *cb)
  425. {
  426. if (!cb) {
  427. chan->cb = &default_channel_callbacks;
  428. return;
  429. }
  430. if (!cb->subbuf_start)
  431. cb->subbuf_start = subbuf_start_default_callback;
  432. if (!cb->buf_mapped)
  433. cb->buf_mapped = buf_mapped_default_callback;
  434. if (!cb->buf_unmapped)
  435. cb->buf_unmapped = buf_unmapped_default_callback;
  436. if (!cb->create_buf_file)
  437. cb->create_buf_file = create_buf_file_default_callback;
  438. if (!cb->remove_buf_file)
  439. cb->remove_buf_file = remove_buf_file_default_callback;
  440. chan->cb = cb;
  441. }
  442. /**
  443. * relay_hotcpu_callback - CPU hotplug callback
  444. * @nb: notifier block
  445. * @action: hotplug action to take
  446. * @hcpu: CPU number
  447. *
  448. * Returns the success/failure of the operation. (%NOTIFY_OK, %NOTIFY_BAD)
  449. */
  450. static int __cpuinit relay_hotcpu_callback(struct notifier_block *nb,
  451. unsigned long action,
  452. void *hcpu)
  453. {
  454. unsigned int hotcpu = (unsigned long)hcpu;
  455. struct rchan *chan;
  456. switch(action) {
  457. case CPU_UP_PREPARE:
  458. case CPU_UP_PREPARE_FROZEN:
  459. mutex_lock(&relay_channels_mutex);
  460. list_for_each_entry(chan, &relay_channels, list) {
  461. if (chan->buf[hotcpu])
  462. continue;
  463. chan->buf[hotcpu] = relay_open_buf(chan, hotcpu);
  464. if(!chan->buf[hotcpu]) {
  465. printk(KERN_ERR
  466. "relay_hotcpu_callback: cpu %d buffer "
  467. "creation failed\n", hotcpu);
  468. mutex_unlock(&relay_channels_mutex);
  469. return notifier_from_errno(-ENOMEM);
  470. }
  471. }
  472. mutex_unlock(&relay_channels_mutex);
  473. break;
  474. case CPU_DEAD:
  475. case CPU_DEAD_FROZEN:
  476. /* No need to flush the cpu : will be flushed upon
  477. * final relay_flush() call. */
  478. break;
  479. }
  480. return NOTIFY_OK;
  481. }
  482. /**
  483. * relay_open - create a new relay channel
  484. * @base_filename: base name of files to create, %NULL for buffering only
  485. * @parent: dentry of parent directory, %NULL for root directory or buffer
  486. * @subbuf_size: size of sub-buffers
  487. * @n_subbufs: number of sub-buffers
  488. * @cb: client callback functions
  489. * @private_data: user-defined data
  490. *
  491. * Returns channel pointer if successful, %NULL otherwise.
  492. *
  493. * Creates a channel buffer for each cpu using the sizes and
  494. * attributes specified. The created channel buffer files
  495. * will be named base_filename0...base_filenameN-1. File
  496. * permissions will be %S_IRUSR.
  497. */
  498. struct rchan *relay_open(const char *base_filename,
  499. struct dentry *parent,
  500. size_t subbuf_size,
  501. size_t n_subbufs,
  502. struct rchan_callbacks *cb,
  503. void *private_data)
  504. {
  505. unsigned int i;
  506. struct rchan *chan;
  507. if (!(subbuf_size && n_subbufs))
  508. return NULL;
  509. if (subbuf_size > UINT_MAX / n_subbufs)
  510. return NULL;
  511. chan = kzalloc(sizeof(struct rchan), GFP_KERNEL);
  512. if (!chan)
  513. return NULL;
  514. chan->version = RELAYFS_CHANNEL_VERSION;
  515. chan->n_subbufs = n_subbufs;
  516. chan->subbuf_size = subbuf_size;
  517. chan->alloc_size = FIX_SIZE(subbuf_size * n_subbufs);
  518. chan->parent = parent;
  519. chan->private_data = private_data;
  520. if (base_filename) {
  521. chan->has_base_filename = 1;
  522. strlcpy(chan->base_filename, base_filename, NAME_MAX);
  523. }
  524. setup_callbacks(chan, cb);
  525. kref_init(&chan->kref);
  526. mutex_lock(&relay_channels_mutex);
  527. for_each_online_cpu(i) {
  528. chan->buf[i] = relay_open_buf(chan, i);
  529. if (!chan->buf[i])
  530. goto free_bufs;
  531. }
  532. list_add(&chan->list, &relay_channels);
  533. mutex_unlock(&relay_channels_mutex);
  534. return chan;
  535. free_bufs:
  536. for_each_possible_cpu(i) {
  537. if (chan->buf[i])
  538. relay_close_buf(chan->buf[i]);
  539. }
  540. kref_put(&chan->kref, relay_destroy_channel);
  541. mutex_unlock(&relay_channels_mutex);
  542. return NULL;
  543. }
  544. EXPORT_SYMBOL_GPL(relay_open);
  545. struct rchan_percpu_buf_dispatcher {
  546. struct rchan_buf *buf;
  547. struct dentry *dentry;
  548. };
  549. /* Called in atomic context. */
  550. static void __relay_set_buf_dentry(void *info)
  551. {
  552. struct rchan_percpu_buf_dispatcher *p = info;
  553. relay_set_buf_dentry(p->buf, p->dentry);
  554. }
  555. /**
  556. * relay_late_setup_files - triggers file creation
  557. * @chan: channel to operate on
  558. * @base_filename: base name of files to create
  559. * @parent: dentry of parent directory, %NULL for root directory
  560. *
  561. * Returns 0 if successful, non-zero otherwise.
  562. *
  563. * Use to setup files for a previously buffer-only channel.
  564. * Useful to do early tracing in kernel, before VFS is up, for example.
  565. */
  566. int relay_late_setup_files(struct rchan *chan,
  567. const char *base_filename,
  568. struct dentry *parent)
  569. {
  570. int err = 0;
  571. unsigned int i, curr_cpu;
  572. unsigned long flags;
  573. struct dentry *dentry;
  574. struct rchan_percpu_buf_dispatcher disp;
  575. if (!chan || !base_filename)
  576. return -EINVAL;
  577. strlcpy(chan->base_filename, base_filename, NAME_MAX);
  578. mutex_lock(&relay_channels_mutex);
  579. /* Is chan already set up? */
  580. if (unlikely(chan->has_base_filename)) {
  581. mutex_unlock(&relay_channels_mutex);
  582. return -EEXIST;
  583. }
  584. chan->has_base_filename = 1;
  585. chan->parent = parent;
  586. curr_cpu = get_cpu();
  587. /*
  588. * The CPU hotplug notifier ran before us and created buffers with
  589. * no files associated. So it's safe to call relay_setup_buf_file()
  590. * on all currently online CPUs.
  591. */
  592. for_each_online_cpu(i) {
  593. if (unlikely(!chan->buf[i])) {
  594. WARN_ONCE(1, KERN_ERR "CPU has no buffer!\n");
  595. err = -EINVAL;
  596. break;
  597. }
  598. dentry = relay_create_buf_file(chan, chan->buf[i], i);
  599. if (unlikely(!dentry)) {
  600. err = -EINVAL;
  601. break;
  602. }
  603. if (curr_cpu == i) {
  604. local_irq_save(flags);
  605. relay_set_buf_dentry(chan->buf[i], dentry);
  606. local_irq_restore(flags);
  607. } else {
  608. disp.buf = chan->buf[i];
  609. disp.dentry = dentry;
  610. smp_mb();
  611. /* relay_channels_mutex must be held, so wait. */
  612. err = smp_call_function_single(i,
  613. __relay_set_buf_dentry,
  614. &disp, 1);
  615. }
  616. if (unlikely(err))
  617. break;
  618. }
  619. put_cpu();
  620. mutex_unlock(&relay_channels_mutex);
  621. return err;
  622. }
  623. /**
  624. * relay_switch_subbuf - switch to a new sub-buffer
  625. * @buf: channel buffer
  626. * @length: size of current event
  627. *
  628. * Returns either the length passed in or 0 if full.
  629. *
  630. * Performs sub-buffer-switch tasks such as invoking callbacks,
  631. * updating padding counts, waking up readers, etc.
  632. */
  633. size_t relay_switch_subbuf(struct rchan_buf *buf, size_t length)
  634. {
  635. void *old, *new;
  636. size_t old_subbuf, new_subbuf;
  637. if (unlikely(length > buf->chan->subbuf_size))
  638. goto toobig;
  639. if (buf->offset != buf->chan->subbuf_size + 1) {
  640. buf->prev_padding = buf->chan->subbuf_size - buf->offset;
  641. old_subbuf = buf->subbufs_produced % buf->chan->n_subbufs;
  642. buf->padding[old_subbuf] = buf->prev_padding;
  643. buf->subbufs_produced++;
  644. if (buf->dentry)
  645. buf->dentry->d_inode->i_size +=
  646. buf->chan->subbuf_size -
  647. buf->padding[old_subbuf];
  648. else
  649. buf->early_bytes += buf->chan->subbuf_size -
  650. buf->padding[old_subbuf];
  651. smp_mb();
  652. if (waitqueue_active(&buf->read_wait))
  653. /*
  654. * Calling wake_up_interruptible() from here
  655. * will deadlock if we happen to be logging
  656. * from the scheduler (trying to re-grab
  657. * rq->lock), so defer it.
  658. */
  659. mod_timer(&buf->timer, jiffies + 1);
  660. }
  661. old = buf->data;
  662. new_subbuf = buf->subbufs_produced % buf->chan->n_subbufs;
  663. new = buf->start + new_subbuf * buf->chan->subbuf_size;
  664. buf->offset = 0;
  665. if (!buf->chan->cb->subbuf_start(buf, new, old, buf->prev_padding)) {
  666. buf->offset = buf->chan->subbuf_size + 1;
  667. return 0;
  668. }
  669. buf->data = new;
  670. buf->padding[new_subbuf] = 0;
  671. if (unlikely(length + buf->offset > buf->chan->subbuf_size))
  672. goto toobig;
  673. return length;
  674. toobig:
  675. buf->chan->last_toobig = length;
  676. return 0;
  677. }
  678. EXPORT_SYMBOL_GPL(relay_switch_subbuf);
  679. /**
  680. * relay_subbufs_consumed - update the buffer's sub-buffers-consumed count
  681. * @chan: the channel
  682. * @cpu: the cpu associated with the channel buffer to update
  683. * @subbufs_consumed: number of sub-buffers to add to current buf's count
  684. *
  685. * Adds to the channel buffer's consumed sub-buffer count.
  686. * subbufs_consumed should be the number of sub-buffers newly consumed,
  687. * not the total consumed.
  688. *
  689. * NOTE. Kernel clients don't need to call this function if the channel
  690. * mode is 'overwrite'.
  691. */
  692. void relay_subbufs_consumed(struct rchan *chan,
  693. unsigned int cpu,
  694. size_t subbufs_consumed)
  695. {
  696. struct rchan_buf *buf;
  697. if (!chan)
  698. return;
  699. if (cpu >= NR_CPUS || !chan->buf[cpu] ||
  700. subbufs_consumed > chan->n_subbufs)
  701. return;
  702. buf = chan->buf[cpu];
  703. if (subbufs_consumed > buf->subbufs_produced - buf->subbufs_consumed)
  704. buf->subbufs_consumed = buf->subbufs_produced;
  705. else
  706. buf->subbufs_consumed += subbufs_consumed;
  707. }
  708. EXPORT_SYMBOL_GPL(relay_subbufs_consumed);
  709. /**
  710. * relay_close - close the channel
  711. * @chan: the channel
  712. *
  713. * Closes all channel buffers and frees the channel.
  714. */
  715. void relay_close(struct rchan *chan)
  716. {
  717. unsigned int i;
  718. if (!chan)
  719. return;
  720. mutex_lock(&relay_channels_mutex);
  721. if (chan->is_global && chan->buf[0])
  722. relay_close_buf(chan->buf[0]);
  723. else
  724. for_each_possible_cpu(i)
  725. if (chan->buf[i])
  726. relay_close_buf(chan->buf[i]);
  727. if (chan->last_toobig)
  728. printk(KERN_WARNING "relay: one or more items not logged "
  729. "[item size (%Zd) > sub-buffer size (%Zd)]\n",
  730. chan->last_toobig, chan->subbuf_size);
  731. list_del(&chan->list);
  732. kref_put(&chan->kref, relay_destroy_channel);
  733. mutex_unlock(&relay_channels_mutex);
  734. }
  735. EXPORT_SYMBOL_GPL(relay_close);
  736. /**
  737. * relay_flush - close the channel
  738. * @chan: the channel
  739. *
  740. * Flushes all channel buffers, i.e. forces buffer switch.
  741. */
  742. void relay_flush(struct rchan *chan)
  743. {
  744. unsigned int i;
  745. if (!chan)
  746. return;
  747. if (chan->is_global && chan->buf[0]) {
  748. relay_switch_subbuf(chan->buf[0], 0);
  749. return;
  750. }
  751. mutex_lock(&relay_channels_mutex);
  752. for_each_possible_cpu(i)
  753. if (chan->buf[i])
  754. relay_switch_subbuf(chan->buf[i], 0);
  755. mutex_unlock(&relay_channels_mutex);
  756. }
  757. EXPORT_SYMBOL_GPL(relay_flush);
  758. /**
  759. * relay_file_open - open file op for relay files
  760. * @inode: the inode
  761. * @filp: the file
  762. *
  763. * Increments the channel buffer refcount.
  764. */
  765. static int relay_file_open(struct inode *inode, struct file *filp)
  766. {
  767. struct rchan_buf *buf = inode->i_private;
  768. kref_get(&buf->kref);
  769. filp->private_data = buf;
  770. return nonseekable_open(inode, filp);
  771. }
  772. /**
  773. * relay_file_mmap - mmap file op for relay files
  774. * @filp: the file
  775. * @vma: the vma describing what to map
  776. *
  777. * Calls upon relay_mmap_buf() to map the file into user space.
  778. */
  779. static int relay_file_mmap(struct file *filp, struct vm_area_struct *vma)
  780. {
  781. struct rchan_buf *buf = filp->private_data;
  782. return relay_mmap_buf(buf, vma);
  783. }
  784. /**
  785. * relay_file_poll - poll file op for relay files
  786. * @filp: the file
  787. * @wait: poll table
  788. *
  789. * Poll implemention.
  790. */
  791. static unsigned int relay_file_poll(struct file *filp, poll_table *wait)
  792. {
  793. unsigned int mask = 0;
  794. struct rchan_buf *buf = filp->private_data;
  795. if (buf->finalized)
  796. return POLLERR;
  797. if (filp->f_mode & FMODE_READ) {
  798. poll_wait(filp, &buf->read_wait, wait);
  799. if (!relay_buf_empty(buf))
  800. mask |= POLLIN | POLLRDNORM;
  801. }
  802. return mask;
  803. }
  804. /**
  805. * relay_file_release - release file op for relay files
  806. * @inode: the inode
  807. * @filp: the file
  808. *
  809. * Decrements the channel refcount, as the filesystem is
  810. * no longer using it.
  811. */
  812. static int relay_file_release(struct inode *inode, struct file *filp)
  813. {
  814. struct rchan_buf *buf = filp->private_data;
  815. kref_put(&buf->kref, relay_remove_buf);
  816. return 0;
  817. }
  818. /*
  819. * relay_file_read_consume - update the consumed count for the buffer
  820. */
  821. static void relay_file_read_consume(struct rchan_buf *buf,
  822. size_t read_pos,
  823. size_t bytes_consumed)
  824. {
  825. size_t subbuf_size = buf->chan->subbuf_size;
  826. size_t n_subbufs = buf->chan->n_subbufs;
  827. size_t read_subbuf;
  828. if (buf->subbufs_produced == buf->subbufs_consumed &&
  829. buf->offset == buf->bytes_consumed)
  830. return;
  831. if (buf->bytes_consumed + bytes_consumed > subbuf_size) {
  832. relay_subbufs_consumed(buf->chan, buf->cpu, 1);
  833. buf->bytes_consumed = 0;
  834. }
  835. buf->bytes_consumed += bytes_consumed;
  836. if (!read_pos)
  837. read_subbuf = buf->subbufs_consumed % n_subbufs;
  838. else
  839. read_subbuf = read_pos / buf->chan->subbuf_size;
  840. if (buf->bytes_consumed + buf->padding[read_subbuf] == subbuf_size) {
  841. if ((read_subbuf == buf->subbufs_produced % n_subbufs) &&
  842. (buf->offset == subbuf_size))
  843. return;
  844. relay_subbufs_consumed(buf->chan, buf->cpu, 1);
  845. buf->bytes_consumed = 0;
  846. }
  847. }
  848. /*
  849. * relay_file_read_avail - boolean, are there unconsumed bytes available?
  850. */
  851. static int relay_file_read_avail(struct rchan_buf *buf, size_t read_pos)
  852. {
  853. size_t subbuf_size = buf->chan->subbuf_size;
  854. size_t n_subbufs = buf->chan->n_subbufs;
  855. size_t produced = buf->subbufs_produced;
  856. size_t consumed = buf->subbufs_consumed;
  857. relay_file_read_consume(buf, read_pos, 0);
  858. consumed = buf->subbufs_consumed;
  859. if (unlikely(buf->offset > subbuf_size)) {
  860. if (produced == consumed)
  861. return 0;
  862. return 1;
  863. }
  864. if (unlikely(produced - consumed >= n_subbufs)) {
  865. consumed = produced - n_subbufs + 1;
  866. buf->subbufs_consumed = consumed;
  867. buf->bytes_consumed = 0;
  868. }
  869. produced = (produced % n_subbufs) * subbuf_size + buf->offset;
  870. consumed = (consumed % n_subbufs) * subbuf_size + buf->bytes_consumed;
  871. if (consumed > produced)
  872. produced += n_subbufs * subbuf_size;
  873. if (consumed == produced) {
  874. if (buf->offset == subbuf_size &&
  875. buf->subbufs_produced > buf->subbufs_consumed)
  876. return 1;
  877. return 0;
  878. }
  879. return 1;
  880. }
  881. /**
  882. * relay_file_read_subbuf_avail - return bytes available in sub-buffer
  883. * @read_pos: file read position
  884. * @buf: relay channel buffer
  885. */
  886. static size_t relay_file_read_subbuf_avail(size_t read_pos,
  887. struct rchan_buf *buf)
  888. {
  889. size_t padding, avail = 0;
  890. size_t read_subbuf, read_offset, write_subbuf, write_offset;
  891. size_t subbuf_size = buf->chan->subbuf_size;
  892. write_subbuf = (buf->data - buf->start) / subbuf_size;
  893. write_offset = buf->offset > subbuf_size ? subbuf_size : buf->offset;
  894. read_subbuf = read_pos / subbuf_size;
  895. read_offset = read_pos % subbuf_size;
  896. padding = buf->padding[read_subbuf];
  897. if (read_subbuf == write_subbuf) {
  898. if (read_offset + padding < write_offset)
  899. avail = write_offset - (read_offset + padding);
  900. } else
  901. avail = (subbuf_size - padding) - read_offset;
  902. return avail;
  903. }
  904. /**
  905. * relay_file_read_start_pos - find the first available byte to read
  906. * @read_pos: file read position
  907. * @buf: relay channel buffer
  908. *
  909. * If the @read_pos is in the middle of padding, return the
  910. * position of the first actually available byte, otherwise
  911. * return the original value.
  912. */
  913. static size_t relay_file_read_start_pos(size_t read_pos,
  914. struct rchan_buf *buf)
  915. {
  916. size_t read_subbuf, padding, padding_start, padding_end;
  917. size_t subbuf_size = buf->chan->subbuf_size;
  918. size_t n_subbufs = buf->chan->n_subbufs;
  919. size_t consumed = buf->subbufs_consumed % n_subbufs;
  920. if (!read_pos)
  921. read_pos = consumed * subbuf_size + buf->bytes_consumed;
  922. read_subbuf = read_pos / subbuf_size;
  923. padding = buf->padding[read_subbuf];
  924. padding_start = (read_subbuf + 1) * subbuf_size - padding;
  925. padding_end = (read_subbuf + 1) * subbuf_size;
  926. if (read_pos >= padding_start && read_pos < padding_end) {
  927. read_subbuf = (read_subbuf + 1) % n_subbufs;
  928. read_pos = read_subbuf * subbuf_size;
  929. }
  930. return read_pos;
  931. }
  932. /**
  933. * relay_file_read_end_pos - return the new read position
  934. * @read_pos: file read position
  935. * @buf: relay channel buffer
  936. * @count: number of bytes to be read
  937. */
  938. static size_t relay_file_read_end_pos(struct rchan_buf *buf,
  939. size_t read_pos,
  940. size_t count)
  941. {
  942. size_t read_subbuf, padding, end_pos;
  943. size_t subbuf_size = buf->chan->subbuf_size;
  944. size_t n_subbufs = buf->chan->n_subbufs;
  945. read_subbuf = read_pos / subbuf_size;
  946. padding = buf->padding[read_subbuf];
  947. if (read_pos % subbuf_size + count + padding == subbuf_size)
  948. end_pos = (read_subbuf + 1) * subbuf_size;
  949. else
  950. end_pos = read_pos + count;
  951. if (end_pos >= subbuf_size * n_subbufs)
  952. end_pos = 0;
  953. return end_pos;
  954. }
  955. /*
  956. * subbuf_read_actor - read up to one subbuf's worth of data
  957. */
  958. static int subbuf_read_actor(size_t read_start,
  959. struct rchan_buf *buf,
  960. size_t avail,
  961. read_descriptor_t *desc,
  962. read_actor_t actor)
  963. {
  964. void *from;
  965. int ret = 0;
  966. from = buf->start + read_start;
  967. ret = avail;
  968. if (copy_to_user(desc->arg.buf, from, avail)) {
  969. desc->error = -EFAULT;
  970. ret = 0;
  971. }
  972. desc->arg.data += ret;
  973. desc->written += ret;
  974. desc->count -= ret;
  975. return ret;
  976. }
  977. typedef int (*subbuf_actor_t) (size_t read_start,
  978. struct rchan_buf *buf,
  979. size_t avail,
  980. read_descriptor_t *desc,
  981. read_actor_t actor);
  982. /*
  983. * relay_file_read_subbufs - read count bytes, bridging subbuf boundaries
  984. */
  985. static ssize_t relay_file_read_subbufs(struct file *filp, loff_t *ppos,
  986. subbuf_actor_t subbuf_actor,
  987. read_actor_t actor,
  988. read_descriptor_t *desc)
  989. {
  990. struct rchan_buf *buf = filp->private_data;
  991. size_t read_start, avail;
  992. int ret;
  993. if (!desc->count)
  994. return 0;
  995. mutex_lock(&filp->f_path.dentry->d_inode->i_mutex);
  996. do {
  997. if (!relay_file_read_avail(buf, *ppos))
  998. break;
  999. read_start = relay_file_read_start_pos(*ppos, buf);
  1000. avail = relay_file_read_subbuf_avail(read_start, buf);
  1001. if (!avail)
  1002. break;
  1003. avail = min(desc->count, avail);
  1004. ret = subbuf_actor(read_start, buf, avail, desc, actor);
  1005. if (desc->error < 0)
  1006. break;
  1007. if (ret) {
  1008. relay_file_read_consume(buf, read_start, ret);
  1009. *ppos = relay_file_read_end_pos(buf, read_start, ret);
  1010. }
  1011. } while (desc->count && ret);
  1012. mutex_unlock(&filp->f_path.dentry->d_inode->i_mutex);
  1013. return desc->written;
  1014. }
  1015. static ssize_t relay_file_read(struct file *filp,
  1016. char __user *buffer,
  1017. size_t count,
  1018. loff_t *ppos)
  1019. {
  1020. read_descriptor_t desc;
  1021. desc.written = 0;
  1022. desc.count = count;
  1023. desc.arg.buf = buffer;
  1024. desc.error = 0;
  1025. return relay_file_read_subbufs(filp, ppos, subbuf_read_actor,
  1026. NULL, &desc);
  1027. }
  1028. static void relay_consume_bytes(struct rchan_buf *rbuf, int bytes_consumed)
  1029. {
  1030. rbuf->bytes_consumed += bytes_consumed;
  1031. if (rbuf->bytes_consumed >= rbuf->chan->subbuf_size) {
  1032. relay_subbufs_consumed(rbuf->chan, rbuf->cpu, 1);
  1033. rbuf->bytes_consumed %= rbuf->chan->subbuf_size;
  1034. }
  1035. }
  1036. static void relay_pipe_buf_release(struct pipe_inode_info *pipe,
  1037. struct pipe_buffer *buf)
  1038. {
  1039. struct rchan_buf *rbuf;
  1040. rbuf = (struct rchan_buf *)page_private(buf->page);
  1041. relay_consume_bytes(rbuf, buf->private);
  1042. }
  1043. static const struct pipe_buf_operations relay_pipe_buf_ops = {
  1044. .can_merge = 0,
  1045. .map = generic_pipe_buf_map,
  1046. .unmap = generic_pipe_buf_unmap,
  1047. .confirm = generic_pipe_buf_confirm,
  1048. .release = relay_pipe_buf_release,
  1049. .steal = generic_pipe_buf_steal,
  1050. .get = generic_pipe_buf_get,
  1051. };
  1052. static void relay_page_release(struct splice_pipe_desc *spd, unsigned int i)
  1053. {
  1054. }
  1055. /*
  1056. * subbuf_splice_actor - splice up to one subbuf's worth of data
  1057. */
  1058. static ssize_t subbuf_splice_actor(struct file *in,
  1059. loff_t *ppos,
  1060. struct pipe_inode_info *pipe,
  1061. size_t len,
  1062. unsigned int flags,
  1063. int *nonpad_ret)
  1064. {
  1065. unsigned int pidx, poff, total_len, subbuf_pages, nr_pages;
  1066. struct rchan_buf *rbuf = in->private_data;
  1067. unsigned int subbuf_size = rbuf->chan->subbuf_size;
  1068. uint64_t pos = (uint64_t) *ppos;
  1069. uint32_t alloc_size = (uint32_t) rbuf->chan->alloc_size;
  1070. size_t read_start = (size_t) do_div(pos, alloc_size);
  1071. size_t read_subbuf = read_start / subbuf_size;
  1072. size_t padding = rbuf->padding[read_subbuf];
  1073. size_t nonpad_end = read_subbuf * subbuf_size + subbuf_size - padding;
  1074. struct page *pages[PIPE_DEF_BUFFERS];
  1075. struct partial_page partial[PIPE_DEF_BUFFERS];
  1076. struct splice_pipe_desc spd = {
  1077. .pages = pages,
  1078. .nr_pages = 0,
  1079. .partial = partial,
  1080. .flags = flags,
  1081. .ops = &relay_pipe_buf_ops,
  1082. .spd_release = relay_page_release,
  1083. };
  1084. ssize_t ret;
  1085. if (rbuf->subbufs_produced == rbuf->subbufs_consumed)
  1086. return 0;
  1087. if (splice_grow_spd(pipe, &spd))
  1088. return -ENOMEM;
  1089. /*
  1090. * Adjust read len, if longer than what is available
  1091. */
  1092. if (len > (subbuf_size - read_start % subbuf_size))
  1093. len = subbuf_size - read_start % subbuf_size;
  1094. subbuf_pages = rbuf->chan->alloc_size >> PAGE_SHIFT;
  1095. pidx = (read_start / PAGE_SIZE) % subbuf_pages;
  1096. poff = read_start & ~PAGE_MASK;
  1097. nr_pages = min_t(unsigned int, subbuf_pages, pipe->buffers);
  1098. for (total_len = 0; spd.nr_pages < nr_pages; spd.nr_pages++) {
  1099. unsigned int this_len, this_end, private;
  1100. unsigned int cur_pos = read_start + total_len;
  1101. if (!len)
  1102. break;
  1103. this_len = min_t(unsigned long, len, PAGE_SIZE - poff);
  1104. private = this_len;
  1105. spd.pages[spd.nr_pages] = rbuf->page_array[pidx];
  1106. spd.partial[spd.nr_pages].offset = poff;
  1107. this_end = cur_pos + this_len;
  1108. if (this_end >= nonpad_end) {
  1109. this_len = nonpad_end - cur_pos;
  1110. private = this_len + padding;
  1111. }
  1112. spd.partial[spd.nr_pages].len = this_len;
  1113. spd.partial[spd.nr_pages].private = private;
  1114. len -= this_len;
  1115. total_len += this_len;
  1116. poff = 0;
  1117. pidx = (pidx + 1) % subbuf_pages;
  1118. if (this_end >= nonpad_end) {
  1119. spd.nr_pages++;
  1120. break;
  1121. }
  1122. }
  1123. ret = 0;
  1124. if (!spd.nr_pages)
  1125. goto out;
  1126. ret = *nonpad_ret = splice_to_pipe(pipe, &spd);
  1127. if (ret < 0 || ret < total_len)
  1128. goto out;
  1129. if (read_start + ret == nonpad_end)
  1130. ret += padding;
  1131. out:
  1132. splice_shrink_spd(pipe, &spd);
  1133. return ret;
  1134. }
  1135. static ssize_t relay_file_splice_read(struct file *in,
  1136. loff_t *ppos,
  1137. struct pipe_inode_info *pipe,
  1138. size_t len,
  1139. unsigned int flags)
  1140. {
  1141. ssize_t spliced;
  1142. int ret;
  1143. int nonpad_ret = 0;
  1144. ret = 0;
  1145. spliced = 0;
  1146. while (len && !spliced) {
  1147. ret = subbuf_splice_actor(in, ppos, pipe, len, flags, &nonpad_ret);
  1148. if (ret < 0)
  1149. break;
  1150. else if (!ret) {
  1151. if (flags & SPLICE_F_NONBLOCK)
  1152. ret = -EAGAIN;
  1153. break;
  1154. }
  1155. *ppos += ret;
  1156. if (ret > len)
  1157. len = 0;
  1158. else
  1159. len -= ret;
  1160. spliced += nonpad_ret;
  1161. nonpad_ret = 0;
  1162. }
  1163. if (spliced)
  1164. return spliced;
  1165. return ret;
  1166. }
  1167. const struct file_operations relay_file_operations = {
  1168. .open = relay_file_open,
  1169. .poll = relay_file_poll,
  1170. .mmap = relay_file_mmap,
  1171. .read = relay_file_read,
  1172. .llseek = no_llseek,
  1173. .release = relay_file_release,
  1174. .splice_read = relay_file_splice_read,
  1175. };
  1176. EXPORT_SYMBOL_GPL(relay_file_operations);
  1177. static __init int relay_init(void)
  1178. {
  1179. hotcpu_notifier(relay_hotcpu_callback, 0);
  1180. return 0;
  1181. }
  1182. early_initcall(relay_init);