#include #include #include #include #include #include #include "data.h" #include "util.h" #include "debug.h" static bool check_pipe(struct perf_data_file *file) { struct stat st; bool is_pipe = false; int fd = perf_data_file__is_read(file) ? STDIN_FILENO : STDOUT_FILENO; if (!file->path) { if (!fstat(fd, &st) && S_ISFIFO(st.st_mode)) is_pipe = true; } else { if (!strcmp(file->path, "-")) is_pipe = true; } if (is_pipe) file->fd = fd; return file->is_pipe = is_pipe; } static int check_backup(struct perf_data_file *file) { struct stat st; if (!stat(file->path, &st) && st.st_size) { /* TODO check errors properly */ char oldname[PATH_MAX]; snprintf(oldname, sizeof(oldname), "%s.old", file->path); unlink(oldname); rename(file->path, oldname); } return 0; } static int open_file_read(struct perf_data_file *file) { struct stat st; int fd; char sbuf[STRERR_BUFSIZE]; fd = open(file->path, O_RDONLY); if (fd < 0) { int err = errno; pr_err("failed to open %s: %s", file->path, str_error_r(err, sbuf, sizeof(sbuf))); if (err == ENOENT && !strcmp(file->path, "perf.data")) pr_err(" (try 'perf record' first)"); pr_err("\n"); return -err; } if (fstat(fd, &st) < 0) goto out_close; if (!file->force && st.st_uid && (st.st_uid != geteuid())) { pr_err("File %s not owned by current user or root (use -f to override)\n", file->path); goto out_close; } if (!st.st_size) { pr_info("zero-sized file (%s), nothing to do!\n", file->path); goto out_close; } file->size = st.st_size; return fd; out_close: close(fd); return -1; } static int open_file_write(struct perf_data_file *file) { int fd; char sbuf[STRERR_BUFSIZE]; if (check_backup(file)) return -1; fd = open(file->path, O_CREAT|O_RDWR|O_TRUNC, S_IRUSR|S_IWUSR); if (fd < 0) pr_err("failed to open %s : %s\n", file->path, str_error_r(errno, sbuf, sizeof(sbuf))); return fd; } static int open_file(struct perf_data_file *file) { int fd; fd = perf_data_file__is_read(file) ? open_file_read(file) : open_file_write(file); file->fd = fd; return fd < 0 ? -1 : 0; } int perf_data_file__open(struct perf_data_file *file) { if (check_pipe(file)) return 0; if (!file->path) file->path = "perf.data"; return open_file(file); } void perf_data_file__close(struct perf_data_file *file) { close(file->fd); } ssize_t perf_data_file__write(struct perf_data_file *file, void *buf, size_t size) { return writen(file->fd, buf, size); } int perf_data_file__switch(struct perf_data_file *file, const char *postfix, size_t pos, bool at_exit) { char *new_filepath; int ret; if (check_pipe(file)) return -EINVAL; if (perf_data_file__is_read(file)) return -EINVAL; if (asprintf(&new_filepath, "%s.%s", file->path, postfix) < 0) return -ENOMEM; /* * Only fire a warning, don't return error, continue fill * original file. */ if (rename(file->path, new_filepath)) pr_warning("Failed to rename %s to %s\n", file->path, new_filepath); if (!at_exit) { close(file->fd); ret = perf_data_file__open(file); if (ret < 0) goto out; if (lseek(file->fd, pos, SEEK_SET) == (off_t)-1) { ret = -errno; pr_debug("Failed to lseek to %zu: %s", pos, strerror(errno)); goto out; } } ret = file->fd; out: free(new_filepath); return ret; } t.cgi/linux/net-next.git/commit/net?id=f7cdee8a79a1cb03fa9ca71b825e72f880b344e1'>bridge: move to workqueue gcNikolay Aleksandrov10-23/+29 2017-02-06bridge: modify bridge and port to have often accessed fields in one cache lineNikolay Aleksandrov1-23/+20 2017-02-06net: dsa: introduce bridge notifierVivien Didelot2-11/+61 2017-02-06net: dsa: add switch notifierVivien Didelot5-0/+70 2017-02-06net: dsa: change state setter scopeVivien Didelot1-6/+9 2017-02-06net: dsa: rollback bridging on errorVivien Didelot1-1/+13 2017-02-06net: dsa: simplify netdevice events handlingVivien Didelot1-28/+16 2017-02-06net: dsa: move netdevice notifier registrationVivien Didelot3-10/+26 2017-02-06net-next: treewide use is_vlan_dev() helper function.Parav Pandit1-1/+2 2017-02-06sctp: process fwd tsn chunk only when prsctp is enabledXin Long1-0/+6 2017-02-06net: remove ndo_neigh_{construct, destroy} from stacked devicesIdo Schimmel3-48/+0 2017-02-05net: remove __napi_complete()Eric Dumazet1-21/+3 2017-02-04net: ipv6: Use compressed IPv6 addresses showing route replace errorDavid Ahern1-1/+1 2017-02-04net: ipv6: Change notifications for multipath delete to RTA_MULTIPATHDavid Ahern2-1/+28 2017-02-04net: ipv6: Change notifications for multipath add to RTA_MULTIPATHDavid Ahern2-3/+53 2017-02-04net: ipv6: Add support to dump multipath routes via RTA_MULTIPATH attributeDavid Ahern2-17/+105 2017-02-04net: ipv6: Allow shorthand delete of all nexthops in multipath routeDavid Ahern1-2/+36 2017-02-03net: skb_needs_check() accepts CHECKSUM_NONE for txEric Dumazet1-3/+4 2017-02-03net: remove support for per driver ndo_busy_poll()Eric Dumazet2-16/+0 2017-02-03Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-nextDavid S. Miller53-640/+576 2017-02-03sched: cls_flower: expose priority to offloading netdeviceJiri Pirko1-0/+3 2017-02-03tcp: clear pfmemalloc on outgoing skbEric Dumazet1-0/+7 2017-02-03net: ipv6: Set protocol to kernel for local routesDavid Ahern1-0/+1 2017-02-03bridge: vlan dst_metadata hooks in ingress and egress pathsRoopa Prabhu6-2/+82 2017-02-03bridge: per vlan dst_metadata netlink supportRoopa Prabhu7-48/+641 2017-02-03net/sched: act_ife: Change to use ife moduleYotam Gigi2-78/+33 2017-02-03net: Introduce ife encapsulation moduleYotam Gigi5-0/+165 2017-02-03net/sched: act_ife: Unexport ife_tlv_meta_encodeYotam Gigi1-2/+2 2017-02-03tcp: add tcp_mss_clamp() helperEric Dumazet