Re: New helper bpf_get_current_pidns_info
Hi, I have resumed work on issue https://github.com/iovisor/bcc/issues/1329. I just added the needed fields in this helper structure and also I updated the bcc code to use this helper, but I have a couple of questions, regarding my implementation. - Should I be reading /proc/self/ns/pid using vfst_stat?. - For Major/Minor I'm not sure if I should be getting the value from stat.dev or stat.rdev. I'm missing to put bcc in a container and replicate the actual issue, but I wanted to share what I have at this point and check if I'm in the right direction or something else is needed in this same helper. BPF_CALL_2(bpf_get_current_pidns_info, void *, buf, u32, size) { struct task_struct *ts = current; struct task_struct *ns_task = NULL; struct pid_namespace *pidns = NULL; pid_t pid = 0; int res = 0; const char ppath[] = "/proc/self/ns/pid"; mm_segment_t oldsegfs; struct kstat stat; if (unlikely(!ts)) return -EINVAL; pidns = task_active_pid_ns(ts); if (unlikely(!pidns)) return -EINVAL; ((struct bpf_current_pidns_info*)buf)->ns_id = (u64) pidns->ns.inum; pid = task_pid_nr_ns(ts, pidns); if (unlikely(!pid)) return -EINVAL; ns_task = find_task_by_pid_ns(pid, pidns); if (unlikely(!ns_task)) return -EINVAL; ((struct bpf_current_pidns_info*)buf)->tgid = (s32)ns_task->tgid; ((struct bpf_current_pidns_info*)buf)->pid = (s32) ns_task->pid; oldsegfs = get_fs(); set_fs(KERNEL_DS); res = vfs_stat((const char __user*)&ppath[0], &stat); set_fs(oldsegfs); if(unlikely(res)) return -EINVAL; ((struct bpf_current_pidns_info*)buf)->major = (u32) MAJOR(stat.dev); ((struct bpf_current_pidns_info*)buf)->minor = (u32) MINOR(stat.dev); return 0; } const struct bpf_func_proto bpf_get_current_pidns_info_proto = { .func = bpf_get_current_pidns_info, .gpl_only = false, .ret_type = RET_INTEGER, .arg1_type = ARG_PTR_TO_RAW_STACK, .arg2_type = ARG_CONST_STACK_SIZE, }; |
|