b3453bf5a8f21891c5ba4b75bd271317c96d3af4
[lttng-modules.git] / src / lttng-statedump-impl.c
1 /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
2 *
3 * lttng-statedump.c
4 *
5 * Linux Trace Toolkit Next Generation Kernel State Dump
6 *
7 * Copyright 2005 Jean-Hugues Deschenes <jean-hugues.deschenes@polymtl.ca>
8 * Copyright 2006-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 *
10 * Changes:
11 * Eric Clement: Add listing of network IP interface
12 * 2006, 2007 Mathieu Desnoyers Fix kernel threads
13 * Various updates
14 */
15
16 #include <linux/init.h>
17 #include <linux/module.h>
18 #include <linux/netlink.h>
19 #include <linux/inet.h>
20 #include <linux/ip.h>
21 #include <linux/kthread.h>
22 #include <linux/proc_fs.h>
23 #include <linux/file.h>
24 #include <linux/interrupt.h>
25 #include <linux/irqnr.h>
26 #include <linux/cpu.h>
27 #include <linux/netdevice.h>
28 #include <linux/inetdevice.h>
29 #include <linux/sched.h>
30 #include <linux/mm.h>
31 #include <linux/swap.h>
32 #include <linux/wait.h>
33 #include <linux/mutex.h>
34 #include <linux/device.h>
35
36 #include <lttng/events.h>
37 #include <lttng/tracer.h>
38 #include <wrapper/irqdesc.h>
39 #include <wrapper/fdtable.h>
40 #include <wrapper/namespace.h>
41 #include <wrapper/irq.h>
42 #include <wrapper/tracepoint.h>
43 #include <wrapper/genhd.h>
44 #include <wrapper/file.h>
45 #include <wrapper/fdtable.h>
46
47 #ifdef CONFIG_LTTNG_HAS_LIST_IRQ
48 #include <linux/irq.h>
49 #endif
50
51 /* Define the tracepoints, but do not build the probes */
52 #define CREATE_TRACE_POINTS
53 #define TRACE_INCLUDE_PATH instrumentation/events
54 #define TRACE_INCLUDE_FILE lttng-statedump
55 #define LTTNG_INSTRUMENTATION
56 #include <instrumentation/events/lttng-statedump.h>
57
58 LTTNG_DEFINE_TRACE(lttng_statedump_block_device,
59 TP_PROTO(struct lttng_session *session,
60 dev_t dev, const char *diskname),
61 TP_ARGS(session, dev, diskname));
62
63 LTTNG_DEFINE_TRACE(lttng_statedump_end,
64 TP_PROTO(struct lttng_session *session),
65 TP_ARGS(session));
66
67 LTTNG_DEFINE_TRACE(lttng_statedump_interrupt,
68 TP_PROTO(struct lttng_session *session,
69 unsigned int irq, const char *chip_name,
70 struct irqaction *action),
71 TP_ARGS(session, irq, chip_name, action));
72
73 LTTNG_DEFINE_TRACE(lttng_statedump_file_descriptor,
74 TP_PROTO(struct lttng_session *session,
75 struct files_struct *files,
76 int fd, const char *filename,
77 unsigned int flags, fmode_t fmode),
78 TP_ARGS(session, files, fd, filename, flags, fmode));
79
80 LTTNG_DEFINE_TRACE(lttng_statedump_start,
81 TP_PROTO(struct lttng_session *session),
82 TP_ARGS(session));
83
84 LTTNG_DEFINE_TRACE(lttng_statedump_process_state,
85 TP_PROTO(struct lttng_session *session,
86 struct task_struct *p,
87 int type, int mode, int submode, int status,
88 struct files_struct *files),
89 TP_ARGS(session, p, type, mode, submode, status, files));
90
91 LTTNG_DEFINE_TRACE(lttng_statedump_process_pid_ns,
92 TP_PROTO(struct lttng_session *session,
93 struct task_struct *p,
94 struct pid_namespace *pid_ns),
95 TP_ARGS(session, p, pid_ns));
96
97 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,6,0))
98 LTTNG_DEFINE_TRACE(lttng_statedump_process_cgroup_ns,
99 TP_PROTO(struct lttng_session *session,
100 struct task_struct *p,
101 struct cgroup_namespace *cgroup_ns),
102 TP_ARGS(session, p, cgroup_ns));
103 #endif
104
105 LTTNG_DEFINE_TRACE(lttng_statedump_process_ipc_ns,
106 TP_PROTO(struct lttng_session *session,
107 struct task_struct *p,
108 struct ipc_namespace *ipc_ns),
109 TP_ARGS(session, p, ipc_ns));
110
111 #ifndef LTTNG_MNT_NS_MISSING_HEADER
112 LTTNG_DEFINE_TRACE(lttng_statedump_process_mnt_ns,
113 TP_PROTO(struct lttng_session *session,
114 struct task_struct *p,
115 struct mnt_namespace *mnt_ns),
116 TP_ARGS(session, p, mnt_ns));
117 #endif
118
119 LTTNG_DEFINE_TRACE(lttng_statedump_process_net_ns,
120 TP_PROTO(struct lttng_session *session,
121 struct task_struct *p,
122 struct net *net_ns),
123 TP_ARGS(session, p, net_ns));
124
125 LTTNG_DEFINE_TRACE(lttng_statedump_process_user_ns,
126 TP_PROTO(struct lttng_session *session,
127 struct task_struct *p,
128 struct user_namespace *user_ns),
129 TP_ARGS(session, p, user_ns));
130
131 LTTNG_DEFINE_TRACE(lttng_statedump_process_uts_ns,
132 TP_PROTO(struct lttng_session *session,
133 struct task_struct *p,
134 struct uts_namespace *uts_ns),
135 TP_ARGS(session, p, uts_ns));
136
137 LTTNG_DEFINE_TRACE(lttng_statedump_process_time_ns,
138 TP_PROTO(struct lttng_session *session,
139 struct task_struct *p,
140 struct time_namespace *time_ns),
141 TP_ARGS(session, p, time_ns));
142
143 LTTNG_DEFINE_TRACE(lttng_statedump_network_interface,
144 TP_PROTO(struct lttng_session *session,
145 struct net_device *dev, struct in_ifaddr *ifa),
146 TP_ARGS(session, dev, ifa));
147
148 #ifdef LTTNG_HAVE_STATEDUMP_CPU_TOPOLOGY
149 LTTNG_DEFINE_TRACE(lttng_statedump_cpu_topology,
150 TP_PROTO(struct lttng_session *session, struct cpuinfo_x86 *c),
151 TP_ARGS(session, c));
152 #endif
153
154 struct lttng_fd_ctx {
155 char *page;
156 struct lttng_session *session;
157 struct files_struct *files;
158 };
159
160 /*
161 * Protected by the trace lock.
162 */
163 static struct delayed_work cpu_work[NR_CPUS];
164 static DECLARE_WAIT_QUEUE_HEAD(statedump_wq);
165 static atomic_t kernel_threads_to_run;
166
167 enum lttng_thread_type {
168 LTTNG_USER_THREAD = 0,
169 LTTNG_KERNEL_THREAD = 1,
170 };
171
172 enum lttng_execution_mode {
173 LTTNG_USER_MODE = 0,
174 LTTNG_SYSCALL = 1,
175 LTTNG_TRAP = 2,
176 LTTNG_IRQ = 3,
177 LTTNG_SOFTIRQ = 4,
178 LTTNG_MODE_UNKNOWN = 5,
179 };
180
181 enum lttng_execution_submode {
182 LTTNG_NONE = 0,
183 LTTNG_UNKNOWN = 1,
184 };
185
186 enum lttng_process_status {
187 LTTNG_UNNAMED = 0,
188 LTTNG_WAIT_FORK = 1,
189 LTTNG_WAIT_CPU = 2,
190 LTTNG_EXIT = 3,
191 LTTNG_ZOMBIE = 4,
192 LTTNG_WAIT = 5,
193 LTTNG_RUN = 6,
194 LTTNG_DEAD = 7,
195 };
196
197
198 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,11,0))
199
200 #define LTTNG_PART_STRUCT_TYPE struct block_device
201
202 static
203 int lttng_get_part_name(struct gendisk *disk, struct block_device *part, char *name_buf)
204 {
205 const char *p;
206
207 p = bdevname(part, name_buf);
208 if (!p)
209 return -ENOSYS;
210
211 return 0;
212 }
213
214 static
215 dev_t lttng_get_part_devt(struct block_device *part)
216 {
217 return part->bd_dev;
218 }
219
220 #else
221
222 #define LTTNG_PART_STRUCT_TYPE struct hd_struct
223
224 static
225 int lttng_get_part_name(struct gendisk *disk, struct hd_struct *part, char *name_buf)
226 {
227 const char *p;
228 struct block_device bdev;
229
230 /*
231 * Create a partial 'struct blockdevice' to use
232 * 'bdevname()' which is a simple wrapper over
233 * 'disk_name()' but has the honor to be EXPORT_SYMBOL.
234 */
235 bdev.bd_disk = disk;
236 bdev.bd_part = part;
237
238 p = bdevname(&bdev, name_buf);
239 if (!p)
240 return -ENOSYS;
241
242 return 0;
243 }
244
245 static
246 dev_t lttng_get_part_devt(struct hd_struct *part)
247 {
248 return part_devt(part);
249 }
250 #endif
251
252 static
253 int lttng_enumerate_block_devices(struct lttng_session *session)
254 {
255 struct class *ptr_block_class;
256 struct device_type *ptr_disk_type;
257 struct class_dev_iter iter;
258 struct device *dev;
259
260 ptr_block_class = wrapper_get_block_class();
261 if (!ptr_block_class)
262 return -ENOSYS;
263 ptr_disk_type = wrapper_get_disk_type();
264 if (!ptr_disk_type) {
265 return -ENOSYS;
266 }
267 class_dev_iter_init(&iter, ptr_block_class, NULL, ptr_disk_type);
268 while ((dev = class_dev_iter_next(&iter))) {
269 struct disk_part_iter piter;
270 struct gendisk *disk = dev_to_disk(dev);
271 LTTNG_PART_STRUCT_TYPE *part;
272
273 /*
274 * Don't show empty devices or things that have been
275 * suppressed
276 */
277 if (get_capacity(disk) == 0 ||
278 (disk->flags & GENHD_FL_SUPPRESS_PARTITION_INFO))
279 continue;
280
281 disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
282 while ((part = disk_part_iter_next(&piter))) {
283 char name_buf[BDEVNAME_SIZE];
284
285 if (lttng_get_part_name(disk, part, name_buf) == -ENOSYS) {
286 disk_part_iter_exit(&piter);
287 class_dev_iter_exit(&iter);
288 return -ENOSYS;
289 }
290 trace_lttng_statedump_block_device(session,
291 lttng_get_part_devt(part), name_buf);
292 }
293 disk_part_iter_exit(&piter);
294 }
295 class_dev_iter_exit(&iter);
296 return 0;
297 }
298
299 #ifdef CONFIG_INET
300
301 static
302 void lttng_enumerate_device(struct lttng_session *session,
303 struct net_device *dev)
304 {
305 struct in_device *in_dev;
306 struct in_ifaddr *ifa;
307
308 if (dev->flags & IFF_UP) {
309 in_dev = in_dev_get(dev);
310 if (in_dev) {
311 for (ifa = in_dev->ifa_list; ifa != NULL;
312 ifa = ifa->ifa_next) {
313 trace_lttng_statedump_network_interface(
314 session, dev, ifa);
315 }
316 in_dev_put(in_dev);
317 }
318 } else {
319 trace_lttng_statedump_network_interface(
320 session, dev, NULL);
321 }
322 }
323
324 static
325 int lttng_enumerate_network_ip_interface(struct lttng_session *session)
326 {
327 struct net_device *dev;
328
329 read_lock(&dev_base_lock);
330 for_each_netdev(&init_net, dev)
331 lttng_enumerate_device(session, dev);
332 read_unlock(&dev_base_lock);
333
334 return 0;
335 }
336 #else /* CONFIG_INET */
337 static inline
338 int lttng_enumerate_network_ip_interface(struct lttng_session *session)
339 {
340 return 0;
341 }
342 #endif /* CONFIG_INET */
343
344 static
345 int lttng_dump_one_fd(const void *p, struct file *file, unsigned int fd)
346 {
347 const struct lttng_fd_ctx *ctx = p;
348 const char *s = d_path(&file->f_path, ctx->page, PAGE_SIZE);
349 unsigned int flags = file->f_flags;
350 struct fdtable *fdt;
351
352 /*
353 * We don't expose kernel internal flags, only userspace-visible
354 * flags.
355 */
356 flags &= ~FMODE_NONOTIFY;
357 fdt = files_fdtable(ctx->files);
358 /*
359 * We need to check here again whether fd is within the fdt
360 * max_fds range, because we might be seeing a different
361 * files_fdtable() than iterate_fd(), assuming only RCU is
362 * protecting the read. In reality, iterate_fd() holds
363 * file_lock, which should ensure the fdt does not change while
364 * the lock is taken, but we are not aware whether this is
365 * guaranteed or not, so play safe.
366 */
367 if (fd < fdt->max_fds && lttng_close_on_exec(fd, fdt))
368 flags |= O_CLOEXEC;
369 if (IS_ERR(s)) {
370 struct dentry *dentry = file->f_path.dentry;
371
372 /* Make sure we give at least some info */
373 spin_lock(&dentry->d_lock);
374 trace_lttng_statedump_file_descriptor(ctx->session,
375 ctx->files, fd, dentry->d_name.name, flags,
376 file->f_mode);
377 spin_unlock(&dentry->d_lock);
378 goto end;
379 }
380 trace_lttng_statedump_file_descriptor(ctx->session,
381 ctx->files, fd, s, flags, file->f_mode);
382 end:
383 return 0;
384 }
385
386 /* Called with task lock held. */
387 static
388 void lttng_enumerate_files(struct lttng_session *session,
389 struct files_struct *files,
390 char *tmp)
391 {
392 struct lttng_fd_ctx ctx = { .page = tmp, .session = session, .files = files, };
393
394 lttng_iterate_fd(files, 0, lttng_dump_one_fd, &ctx);
395 }
396
397 #ifdef LTTNG_HAVE_STATEDUMP_CPU_TOPOLOGY
398 static
399 int lttng_enumerate_cpu_topology(struct lttng_session *session)
400 {
401 int cpu;
402 const cpumask_t *cpumask = cpu_possible_mask;
403
404 for (cpu = cpumask_first(cpumask); cpu < nr_cpu_ids;
405 cpu = cpumask_next(cpu, cpumask)) {
406 trace_lttng_statedump_cpu_topology(session, &cpu_data(cpu));
407 }
408
409 return 0;
410 }
411 #else
412 static
413 int lttng_enumerate_cpu_topology(struct lttng_session *session)
414 {
415 return 0;
416 }
417 #endif
418
419 #if 0
420 /*
421 * FIXME: we cannot take a mmap_sem while in a RCU read-side critical section
422 * (scheduling in atomic). Normally, the tasklist lock protects this kind of
423 * iteration, but it is not exported to modules.
424 */
425 static
426 void lttng_enumerate_task_vm_maps(struct lttng_session *session,
427 struct task_struct *p)
428 {
429 struct mm_struct *mm;
430 struct vm_area_struct *map;
431 unsigned long ino;
432
433 /* get_task_mm does a task_lock... */
434 mm = get_task_mm(p);
435 if (!mm)
436 return;
437
438 map = mm->mmap;
439 if (map) {
440 down_read(&mm->mmap_sem);
441 while (map) {
442 if (map->vm_file)
443 ino = map->vm_file->lttng_f_dentry->d_inode->i_ino;
444 else
445 ino = 0;
446 trace_lttng_statedump_vm_map(session, p, map, ino);
447 map = map->vm_next;
448 }
449 up_read(&mm->mmap_sem);
450 }
451 mmput(mm);
452 }
453
454 static
455 int lttng_enumerate_vm_maps(struct lttng_session *session)
456 {
457 struct task_struct *p;
458
459 rcu_read_lock();
460 for_each_process(p)
461 lttng_enumerate_task_vm_maps(session, p);
462 rcu_read_unlock();
463 return 0;
464 }
465 #endif
466
467 #ifdef CONFIG_LTTNG_HAS_LIST_IRQ
468
469 static
470 int lttng_list_interrupts(struct lttng_session *session)
471 {
472 unsigned int irq;
473 unsigned long flags = 0;
474 struct irq_desc *desc;
475
476 #define irq_to_desc wrapper_irq_to_desc
477 /* needs irq_desc */
478 for_each_irq_desc(irq, desc) {
479 struct irqaction *action;
480 const char *irq_chip_name =
481 irq_desc_get_chip(desc)->name ? : "unnamed_irq_chip";
482
483 local_irq_save(flags);
484 raw_spin_lock(&desc->lock);
485 for (action = desc->action; action; action = action->next) {
486 trace_lttng_statedump_interrupt(session,
487 irq, irq_chip_name, action);
488 }
489 raw_spin_unlock(&desc->lock);
490 local_irq_restore(flags);
491 }
492 return 0;
493 #undef irq_to_desc
494 }
495 #else
496 static inline
497 int lttng_list_interrupts(struct lttng_session *session)
498 {
499 return 0;
500 }
501 #endif
502
503 /*
504 * Statedump the task's namespaces using the proc filesystem inode number as
505 * the unique identifier. The user and pid ns are nested and will be dumped
506 * recursively.
507 *
508 * Called with task lock held.
509 */
510 static
511 void lttng_statedump_process_ns(struct lttng_session *session,
512 struct task_struct *p,
513 enum lttng_thread_type type,
514 enum lttng_execution_mode mode,
515 enum lttng_execution_submode submode,
516 enum lttng_process_status status)
517 {
518 struct nsproxy *proxy;
519 struct pid_namespace *pid_ns;
520 struct user_namespace *user_ns;
521
522 /*
523 * The pid and user namespaces are special, they are nested and
524 * accessed with specific functions instead of the nsproxy struct
525 * like the other namespaces.
526 */
527 pid_ns = task_active_pid_ns(p);
528 do {
529 trace_lttng_statedump_process_pid_ns(session, p, pid_ns);
530 pid_ns = pid_ns ? pid_ns->parent : NULL;
531 } while (pid_ns);
532
533
534 user_ns = task_cred_xxx(p, user_ns);
535 do {
536 trace_lttng_statedump_process_user_ns(session, p, user_ns);
537 /*
538 * trace_lttng_statedump_process_user_ns() internally
539 * checks whether user_ns is NULL. While this does not
540 * appear to be a possible return value for
541 * task_cred_xxx(), err on the safe side and check
542 * for NULL here as well to be consistent with the
543 * paranoid behavior of
544 * trace_lttng_statedump_process_user_ns().
545 */
546 user_ns = user_ns ? user_ns->lttng_user_ns_parent : NULL;
547 } while (user_ns);
548
549 /*
550 * Back and forth on locking strategy within Linux upstream for nsproxy.
551 * See Linux upstream commit 728dba3a39c66b3d8ac889ddbe38b5b1c264aec3
552 * "namespaces: Use task_lock and not rcu to protect nsproxy"
553 * for details.
554 */
555 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,17,0) || \
556 LTTNG_UBUNTU_KERNEL_RANGE(3,13,11,36, 3,14,0,0) || \
557 LTTNG_UBUNTU_KERNEL_RANGE(3,16,1,11, 3,17,0,0) || \
558 LTTNG_RHEL_KERNEL_RANGE(3,10,0,229,13,0, 3,11,0,0,0,0))
559 proxy = p->nsproxy;
560 #else
561 rcu_read_lock();
562 proxy = task_nsproxy(p);
563 #endif
564 if (proxy) {
565 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,6,0))
566 trace_lttng_statedump_process_cgroup_ns(session, p, proxy->cgroup_ns);
567 #endif
568 trace_lttng_statedump_process_ipc_ns(session, p, proxy->ipc_ns);
569 #ifndef LTTNG_MNT_NS_MISSING_HEADER
570 trace_lttng_statedump_process_mnt_ns(session, p, proxy->mnt_ns);
571 #endif
572 trace_lttng_statedump_process_net_ns(session, p, proxy->net_ns);
573 trace_lttng_statedump_process_uts_ns(session, p, proxy->uts_ns);
574 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,6,0))
575 trace_lttng_statedump_process_time_ns(session, p, proxy->time_ns);
576 #endif
577 }
578 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,17,0) || \
579 LTTNG_UBUNTU_KERNEL_RANGE(3,13,11,36, 3,14,0,0) || \
580 LTTNG_UBUNTU_KERNEL_RANGE(3,16,1,11, 3,17,0,0) || \
581 LTTNG_RHEL_KERNEL_RANGE(3,10,0,229,13,0, 3,11,0,0,0,0))
582 /* (nothing) */
583 #else
584 rcu_read_unlock();
585 #endif
586 }
587
588 static
589 int lttng_enumerate_process_states(struct lttng_session *session)
590 {
591 struct task_struct *g, *p;
592 char *tmp;
593
594 tmp = (char *) __get_free_page(GFP_KERNEL);
595 if (!tmp)
596 return -ENOMEM;
597
598 rcu_read_lock();
599 for_each_process(g) {
600 struct files_struct *prev_files = NULL;
601
602 p = g;
603 do {
604 enum lttng_execution_mode mode =
605 LTTNG_MODE_UNKNOWN;
606 enum lttng_execution_submode submode =
607 LTTNG_UNKNOWN;
608 enum lttng_process_status status;
609 enum lttng_thread_type type;
610 struct files_struct *files;
611
612 task_lock(p);
613 if (p->exit_state == EXIT_ZOMBIE)
614 status = LTTNG_ZOMBIE;
615 else if (p->exit_state == EXIT_DEAD)
616 status = LTTNG_DEAD;
617 else if (p->state == TASK_RUNNING) {
618 /* Is this a forked child that has not run yet? */
619 if (list_empty(&p->rt.run_list))
620 status = LTTNG_WAIT_FORK;
621 else
622 /*
623 * All tasks are considered as wait_cpu;
624 * the viewer will sort out if the task
625 * was really running at this time.
626 */
627 status = LTTNG_WAIT_CPU;
628 } else if (p->state &
629 (TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE)) {
630 /* Task is waiting for something to complete */
631 status = LTTNG_WAIT;
632 } else
633 status = LTTNG_UNNAMED;
634 submode = LTTNG_NONE;
635
636 /*
637 * Verification of t->mm is to filter out kernel
638 * threads; Viewer will further filter out if a
639 * user-space thread was in syscall mode or not.
640 */
641 if (p->mm)
642 type = LTTNG_USER_THREAD;
643 else
644 type = LTTNG_KERNEL_THREAD;
645 files = p->files;
646
647 trace_lttng_statedump_process_state(session,
648 p, type, mode, submode, status, files);
649 lttng_statedump_process_ns(session,
650 p, type, mode, submode, status);
651 /*
652 * As an optimisation for the common case, do not
653 * repeat information for the same files_struct in
654 * two consecutive threads. This is the common case
655 * for threads sharing the same fd table. RCU guarantees
656 * that the same files_struct pointer is not re-used
657 * throughout processes/threads iteration.
658 */
659 if (files && files != prev_files) {
660 lttng_enumerate_files(session, files, tmp);
661 prev_files = files;
662 }
663 task_unlock(p);
664 } while_each_thread(g, p);
665 }
666 rcu_read_unlock();
667
668 free_page((unsigned long) tmp);
669
670 return 0;
671 }
672
673 static
674 void lttng_statedump_work_func(struct work_struct *work)
675 {
676 if (atomic_dec_and_test(&kernel_threads_to_run))
677 /* If we are the last thread, wake up do_lttng_statedump */
678 wake_up(&statedump_wq);
679 }
680
681 static
682 int do_lttng_statedump(struct lttng_session *session)
683 {
684 int cpu, ret;
685
686 trace_lttng_statedump_start(session);
687 ret = lttng_enumerate_process_states(session);
688 if (ret)
689 return ret;
690 /*
691 * FIXME
692 * ret = lttng_enumerate_vm_maps(session);
693 * if (ret)
694 * return ret;
695 */
696 ret = lttng_list_interrupts(session);
697 if (ret)
698 return ret;
699 ret = lttng_enumerate_network_ip_interface(session);
700 if (ret)
701 return ret;
702 ret = lttng_enumerate_block_devices(session);
703 switch (ret) {
704 case 0:
705 break;
706 case -ENOSYS:
707 printk(KERN_WARNING "LTTng: block device enumeration is not supported by kernel\n");
708 break;
709 default:
710 return ret;
711 }
712 ret = lttng_enumerate_cpu_topology(session);
713 if (ret)
714 return ret;
715
716 /* TODO lttng_dump_idt_table(session); */
717 /* TODO lttng_dump_softirq_vec(session); */
718 /* TODO lttng_list_modules(session); */
719 /* TODO lttng_dump_swap_files(session); */
720
721 /*
722 * Fire off a work queue on each CPU. Their sole purpose in life
723 * is to guarantee that each CPU has been in a state where is was in
724 * syscall mode (i.e. not in a trap, an IRQ or a soft IRQ).
725 */
726 get_online_cpus();
727 atomic_set(&kernel_threads_to_run, num_online_cpus());
728 for_each_online_cpu(cpu) {
729 INIT_DELAYED_WORK(&cpu_work[cpu], lttng_statedump_work_func);
730 schedule_delayed_work_on(cpu, &cpu_work[cpu], 0);
731 }
732 /* Wait for all threads to run */
733 __wait_event(statedump_wq, (atomic_read(&kernel_threads_to_run) == 0));
734 put_online_cpus();
735 /* Our work is done */
736 trace_lttng_statedump_end(session);
737 return 0;
738 }
739
740 /*
741 * Called with session mutex held.
742 */
743 int lttng_statedump_start(struct lttng_session *session)
744 {
745 return do_lttng_statedump(session);
746 }
747 EXPORT_SYMBOL_GPL(lttng_statedump_start);
748
749 static
750 int __init lttng_statedump_init(void)
751 {
752 /*
753 * Allow module to load even if the fixup cannot be done. This
754 * will allow seemless transition when the underlying issue fix
755 * is merged into the Linux kernel, and when tracepoint.c
756 * "tracepoint_module_notify" is turned into a static function.
757 */
758 (void) wrapper_lttng_fixup_sig(THIS_MODULE);
759 return 0;
760 }
761
762 module_init(lttng_statedump_init);
763
764 static
765 void __exit lttng_statedump_exit(void)
766 {
767 }
768
769 module_exit(lttng_statedump_exit);
770
771 MODULE_LICENSE("GPL and additional rights");
772 MODULE_AUTHOR("Jean-Hugues Deschenes");
773 MODULE_DESCRIPTION("LTTng statedump provider");
774 MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION) "."
775 __stringify(LTTNG_MODULES_MINOR_VERSION) "."
776 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION)
777 LTTNG_MODULES_EXTRAVERSION);
This page took 0.042795 seconds and 3 git commands to generate.