1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2006 Cluster File Systems, Inc. All rights reserved.
6 * This file is part of the Lustre file system, http://www.lustre.org
7 * Lustre is a trademark of Cluster File Systems, Inc.
9 * This file is confidential source code owned by Cluster File Systems.
10 * No viewing, modification, compilation, redistribution, or any other
11 * form of use is permitted except through a signed license agreement.
13 * If you have not signed such an agreement, then you have no rights to
14 * this file. Please destroy it immediately and contact CFS.
21 static struct semaphore ptltrace_mutex;
22 static struct semaphore ptltrace_signal;
25 kptllnd_ptltrace_to_file(char *filename)
27 CFS_DECL_JOURNAL_DATA;
38 CWARN("dumping ptltrace to %s\n", filename);
40 LIBCFS_ALLOC(tmpbuf, PAGE_SIZE);
42 CERROR("Can't allocate page buffer to dump %s\n", filename);
48 filp = cfs_filp_open(filename,
49 O_CREAT|O_EXCL|O_WRONLY|O_LARGEFILE, 0600, &rc);
51 CERROR("Error %d creating %s\n", rc, filename);
59 len = ptl_proc_read(tmpbuf, &start, offset,
60 PAGE_SIZE, &eof, NULL);
62 /* we don't allow ptl_proc_read to mimic case 0 or 1 behavior
63 * for a proc_read method, only #2: from proc_file_read
65 * 2) Set *start = an address within the buffer.
66 * Put the data of the requested offset at *start.
67 * Return the number of bytes of data placed there.
68 * If this number is greater than zero and you
69 * didn't signal eof and the reader is prepared to
70 * take more data you will be called again with the
71 * requested offset advanced by the number of bytes
75 if (len == 0) /* end of file */
79 CERROR("ptl_proc_read: error %d\n", len);
83 LASSERT (start >= tmpbuf && start + len <= tmpbuf + PAGE_SIZE);
85 rc = cfs_filp_write(filp, start, len, cfs_filp_poff(filp));
88 CERROR("Error %d writing %s\n", rc, filename);
90 CERROR("Partial write %d(%d) to %s\n",
100 rc = cfs_filp_fsync(filp);
102 CERROR("Error %d syncing %s\n", rc, filename);
104 cfs_filp_close(filp);
107 LIBCFS_FREE(tmpbuf, PAGE_SIZE);
111 kptllnd_dump_ptltrace_thread(void *arg)
113 static char fname[1024];
115 libcfs_daemonize("ptltracedump");
117 /* serialise with other instances of me */
118 mutex_down(&ptltrace_mutex);
120 snprintf(fname, sizeof(fname), "%s.%ld.%ld",
121 *kptllnd_tunables.kptl_ptltrace_basename,
122 cfs_time_current_sec(), (long)arg);
124 kptllnd_ptltrace_to_file(fname);
126 mutex_up(&ptltrace_mutex);
128 /* unblock my creator */
129 mutex_up(&ptltrace_signal);
135 kptllnd_dump_ptltrace(void)
139 if (!*kptllnd_tunables.kptl_ptltrace_on_timeout)
142 rc = cfs_kernel_thread(kptllnd_dump_ptltrace_thread,
143 (void *)(long)cfs_curproc_pid(),
144 CLONE_VM | CLONE_FS | CLONE_FILES);
146 CERROR("Error %d starting ptltrace dump thread\n", rc);
148 /* block until thread completes */
149 mutex_down(&ptltrace_signal);
154 kptllnd_init_ptltrace(void)
156 init_mutex(&ptltrace_mutex);
157 init_mutex_locked(&ptltrace_signal);
163 kptllnd_dump_ptltrace(void)
168 kptllnd_init_ptltrace(void)