relay.c 33 KB

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