char *path; /* path to device special file */
char *buts_name; /* name returned from bt kernel code */
struct pdc_stats *stats;
- int fd, idx, ncpus;
+ int fd, ncpus;
unsigned long long drops;
/*
"\t-w Stop after defined time, in seconds\n" \
"\t-a Only trace specified actions. See documentation\n" \
"\t-A Give trace mask as a single value. See documentation\n" \
- "\t-b Sub buffer size in KiB\n" \
- "\t-n Number of sub buffers\n" \
+ "\t-b Sub buffer size in KiB (default 512)\n" \
+ "\t-n Number of sub buffers (default 4)\n" \
"\t-l Run in network listen mode (blktrace server)\n" \
"\t-h Run in network client mode, connecting to the given host\n" \
"\t-p Network port to use (default 8462)\n" \
return new;
}
-static int my_mlock(const void *addr, size_t len)
+static int my_mlock(struct tracer *tp,
+ const void *addr, size_t len)
{
- int ret;
+ int ret, retry = 0;
do {
ret = mlock(addr, len);
+ if ((retry >= 10) && tp && tp->is_done)
+ break;
+ retry++;
} while (ret < 0 && handle_mem_failure(len));
return ret;
}
-static int setup_mmap(int fd, unsigned int maxlen, struct mmap_info *mip)
+static int setup_mmap(int fd, unsigned int maxlen,
+ struct mmap_info *mip,
+ struct tracer *tp)
{
if (mip->fs_off + maxlen > mip->fs_buf_len) {
unsigned long nr = max(16, mip->buf_nr);
perror("setup_mmap: mmap");
return 1;
}
- my_mlock(mip->fs_buf, mip->fs_buf_len);
+ if (my_mlock(tp, mip->fs_buf, mip->fs_buf_len) < 0) {
+ perror("setup_mlock: mlock");
+ return 1;
+ }
}
return 0;
memset(dpp, 0, sizeof(*dpp));
dpp->path = strdup(path);
dpp->fd = fd;
- dpp->idx = ndevs++;
+ ndevs++;
list_add_tail(&dpp->head, &devpaths);
return 0;
* the whole structures, as the other fields
* are "static".
*/
- prev = realloc(prev->buf, sizeof(*prev) + tot_len);
+ prev = realloc(prev, sizeof(*prev) + tot_len);
prev->buf = (void *)(prev + 1);
}
if (pfd->revents & POLLIN || force_read) {
mip = &iop->mmap_info;
- ret = setup_mmap(iop->ofd, buf_size, mip);
+ ret = setup_mmap(iop->ofd, buf_size, mip, tp);
if (ret < 0) {
pfd->events = 0;
break;
return 1;
}
- if (statfs(debugfs_path, &st) < 0 || st.f_type != (long)DEBUGFS_TYPE) {
+ if (statfs(debugfs_path, &st) < 0) {
fprintf(stderr, "Invalid debug path %s: %d/%s\n",
debugfs_path, errno, strerror(errno));
return 1;
}
+ if (st.f_type != (long)DEBUGFS_TYPE) {
+ fprintf(stderr, "Debugfs is not mounted at %s\n", debugfs_path);
+ return 1;
+ }
+
if (act_mask_tmp != 0)
act_mask = act_mask_tmp;
piped_output = 1;
handle_pfds = handle_pfds_entries;
pfp = stdout;
- setvbuf(pfp, NULL, _IONBF, 0);
+ if (setvbuf(pfp, NULL, _IONBF, 0)) {
+ perror("setvbuf stdout");
+ return 1;
+ }
} else
handle_pfds = handle_pfds_file;
return 0;
struct io_info *iop = &dpp->ios[bnh->cpu];
struct mmap_info *mip = &iop->mmap_info;
- if (setup_mmap(iop->ofd, bnh->len, &iop->mmap_info)) {
+ if (setup_mmap(iop->ofd, bnh->len, &iop->mmap_info, NULL)) {
fprintf(stderr, "ncd(%s:%d): mmap failed\n",
nc->ch->hostname, nc->fd);
exit(1);