Skip to content

Commit

Permalink
Fix zfs send progress reporting
Browse files Browse the repository at this point in the history
The progress of a send is supposed to be reported by `zfs send -v`, but
it is not.  This works by creating a new user thread (with
pthread_create()) which does ZFS_IOC_SEND_PROGRESS ioctls to check how
much progress has been made.  This IOCTL finds the specified send (since
there may be multiple concurrent sends in the system).  The IOCTL also
checks that the specified send was started by the current process.

On Linux, different threads of the same process are represented as
different `struct task_struct`s (and, confusingly, have different
PID's).  To check if if two threads are in the same process, we need to
check if they have the same `struct task_struct:group_leader`.

We used to to this correctly, but it was inadvertently changed by
30af21b (Redacted Send) to simply check if the current
`struct task_struct` is the one that started the send.

This commit changes the code back to checking if the send was started by
a `struct task_struct` with the same `group_leader` as the calling
thread.

Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Reviewed-by: Chris Wedgwood <cw@f00f.org>
Reviewed-by: Paul Dagnelie <pcd@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
Closes #10215 
Closes #10216
  • Loading branch information
ahrens authored Apr 20, 2020
1 parent c614fd6 commit 1f043c8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
7 changes: 7 additions & 0 deletions include/os/freebsd/spl/sys/proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,11 @@ do_thread_create(caddr_t stk, size_t stksize, void (*proc)(void *), void *arg,

int uread(proc_t *, void *, size_t, uintptr_t);
int uwrite(proc_t *, void *, size_t, uintptr_t);

static inline boolean_t
zfs_proc_is_caller(proc_t *p)
{
return (p == curproc);
}

#endif /* _OPENSOLARIS_SYS_PROC_H_ */
7 changes: 7 additions & 0 deletions include/os/linux/spl/sys/proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,17 @@
#define _SPL_PROC_H

#include <linux/proc_fs.h>
#include <linux/sched.h>

extern struct proc_dir_entry *proc_spl_kstat;

int spl_proc_init(void);
void spl_proc_fini(void);

static inline boolean_t
zfs_proc_is_caller(struct task_struct *t)
{
return (t->group_leader == current->group_leader);
}

#endif /* SPL_PROC_H */
2 changes: 1 addition & 1 deletion module/zfs/zfs_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -5468,7 +5468,7 @@ zfs_ioc_send_progress(zfs_cmd_t *zc)
for (dsp = list_head(&ds->ds_sendstreams); dsp != NULL;
dsp = list_next(&ds->ds_sendstreams, dsp)) {
if (dsp->dss_outfd == zc->zc_cookie &&
dsp->dss_proc == curproc)
zfs_proc_is_caller(dsp->dss_proc))
break;
}

Expand Down

0 comments on commit 1f043c8

Please sign in to comment.