relay.c 33 KB

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