relay.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367
  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. 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. umode_t 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. .nr_pages_max = PIPE_DEF_BUFFERS,
  1080. .partial = partial,
  1081. .flags = flags,
  1082. .ops = &relay_pipe_buf_ops,
  1083. .spd_release = relay_page_release,
  1084. };
  1085. ssize_t ret;
  1086. if (rbuf->subbufs_produced == rbuf->subbufs_consumed)
  1087. return 0;
  1088. if (splice_grow_spd(pipe, &spd))
  1089. return -ENOMEM;
  1090. /*
  1091. * Adjust read len, if longer than what is available
  1092. */
  1093. if (len > (subbuf_size - read_start % subbuf_size))
  1094. len = subbuf_size - read_start % subbuf_size;
  1095. subbuf_pages = rbuf->chan->alloc_size >> PAGE_SHIFT;
  1096. pidx = (read_start / PAGE_SIZE) % subbuf_pages;
  1097. poff = read_start & ~PAGE_MASK;
  1098. nr_pages = min_t(unsigned int, subbuf_pages, pipe->buffers);
  1099. for (total_len = 0; spd.nr_pages < nr_pages; spd.nr_pages++) {
  1100. unsigned int this_len, this_end, private;
  1101. unsigned int cur_pos = read_start + total_len;
  1102. if (!len)
  1103. break;
  1104. this_len = min_t(unsigned long, len, PAGE_SIZE - poff);
  1105. private = this_len;
  1106. spd.pages[spd.nr_pages] = rbuf->page_array[pidx];
  1107. spd.partial[spd.nr_pages].offset = poff;
  1108. this_end = cur_pos + this_len;
  1109. if (this_end >= nonpad_end) {
  1110. this_len = nonpad_end - cur_pos;
  1111. private = this_len + padding;
  1112. }
  1113. spd.partial[spd.nr_pages].len = this_len;
  1114. spd.partial[spd.nr_pages].private = private;
  1115. len -= this_len;
  1116. total_len += this_len;
  1117. poff = 0;
  1118. pidx = (pidx + 1) % subbuf_pages;
  1119. if (this_end >= nonpad_end) {
  1120. spd.nr_pages++;
  1121. break;
  1122. }
  1123. }
  1124. ret = 0;
  1125. if (!spd.nr_pages)
  1126. goto out;
  1127. ret = *nonpad_ret = splice_to_pipe(pipe, &spd);
  1128. if (ret < 0 || ret < total_len)
  1129. goto out;
  1130. if (read_start + ret == nonpad_end)
  1131. ret += padding;
  1132. out:
  1133. splice_shrink_spd(&spd);
  1134. return ret;
  1135. }
  1136. static ssize_t relay_file_splice_read(struct file *in,
  1137. loff_t *ppos,
  1138. struct pipe_inode_info *pipe,
  1139. size_t len,
  1140. unsigned int flags)
  1141. {
  1142. ssize_t spliced;
  1143. int ret;
  1144. int nonpad_ret = 0;
  1145. ret = 0;
  1146. spliced = 0;
  1147. while (len && !spliced) {
  1148. ret = subbuf_splice_actor(in, ppos, pipe, len, flags, &nonpad_ret);
  1149. if (ret < 0)
  1150. break;
  1151. else if (!ret) {
  1152. if (flags & SPLICE_F_NONBLOCK)
  1153. ret = -EAGAIN;
  1154. break;
  1155. }
  1156. *ppos += ret;
  1157. if (ret > len)
  1158. len = 0;
  1159. else
  1160. len -= ret;
  1161. spliced += nonpad_ret;
  1162. nonpad_ret = 0;
  1163. }
  1164. if (spliced)
  1165. return spliced;
  1166. return ret;
  1167. }
  1168. const struct file_operations relay_file_operations = {
  1169. .open = relay_file_open,
  1170. .poll = relay_file_poll,
  1171. .mmap = relay_file_mmap,
  1172. .read = relay_file_read,
  1173. .llseek = no_llseek,
  1174. .release = relay_file_release,
  1175. .splice_read = relay_file_splice_read,
  1176. };
  1177. EXPORT_SYMBOL_GPL(relay_file_operations);
  1178. static __init int relay_init(void)
  1179. {
  1180. hotcpu_notifier(relay_hotcpu_callback, 0);
  1181. return 0;
  1182. }
  1183. early_initcall(relay_init);