Message ID | 20191030233641.30123-1-marcos.souza.org@gmail.com (mailing list archive) |
---|---|
Headers | show |
Series | balance: check balance errors on background | expand |
On 10/31/19 7:36 AM, Marcos Paulo de Souza wrote: > From: Marcos Paulo de Souza <mpdesouza@suse.com> > > The first patch removes the close/open operation of stderr, so we can receive > errors of balance when starting in the background. > > The second patch waits up to three seconds after started the balance process, to > check is some problem happened to the balance process. This is done only when > the user issues the "balance start" in background mode. > > This was tested by issuing running "btrfs balance start --background > --full-balance <path>", when the balance started, issue the same command again > in the same terminal: > > # ./btrfs balance start --background --full-balance /mnt > # ./btrfs balance start --background --full-balance /mnt > ERROR: error during balancing '/mnt': Operation now in progress > > These two patches together fixes the issue 167[1]. > > Please review, > Thanks. > > [1]: https://github.com/kdave/btrfs-progs/issues/167 David, ----- (To fix this, the parent process should wait a bit if the forked background process still runs and report errors otherwise. There are no blocking calls when the 2nd ioctl is called, so a few seconds should be enough.) ----- This approach might work in most of the cases. However user thread waiting for 3 sec is not a deterministic way to find if the balance was started successfully in the kernel. IMO. Instead can we use the balance start ioctl to spin a kthread to run the actual balance that is __btrfs_balance(). With means until call to __btrfs_balance() we shall use ioctl-thread and to spin up kthread to run __btrfs_balance() and return the ioctl thread with the interim status (So for the --no-background user thread has to monitor the balance status using the balance progress ioctl and return when the status becomes completed and also it should call balance control ioctl if the received sigint). We do use kthread for balance, if mount thread has to resume the balance. so its a kind of extension to it. But in the view of the backward btrfs-progs compatibility (that is new kernel with old progs) it looks like we need a new balance-ioctl altogether, but the question is if its too much infrastructure changes, which otherwise might have worked fairly well with a 3 sec delay? What do you think? I think its a good idea to fix it in the right way. Thanks, Anand > Marcos Paulo de Souza (2): > btrfs-progs: balance: Don't set stderr to /dev/null on balance_start > btrfs-progs: balance: Verify EINPROGRESS on background balance > > cmds/balance.c | 19 +++++++++++++++---- > 1 file changed, 15 insertions(+), 4 deletions(-) >
On Thu, Oct 31, 2019 at 06:00:35PM +0800, Anand Jain wrote: > On 10/31/19 7:36 AM, Marcos Paulo de Souza wrote: > > From: Marcos Paulo de Souza <mpdesouza@suse.com> > > > > The first patch removes the close/open operation of stderr, so we can receive > > errors of balance when starting in the background. > > > > The second patch waits up to three seconds after started the balance process, to > > check is some problem happened to the balance process. This is done only when > > the user issues the "balance start" in background mode. > > > > This was tested by issuing running "btrfs balance start --background > > --full-balance <path>", when the balance started, issue the same command again > > in the same terminal: > > > > # ./btrfs balance start --background --full-balance /mnt > > # ./btrfs balance start --background --full-balance /mnt > > ERROR: error during balancing '/mnt': Operation now in progress > > > > These two patches together fixes the issue 167[1]. > > > > Please review, > > Thanks. > > > > [1]: https://github.com/kdave/btrfs-progs/issues/167 > > > David, > > ----- > (To fix this, the parent process should wait a bit if the forked > background process still runs and report errors otherwise. There are no > blocking calls when the 2nd ioctl is called, so a few seconds should be > enough.) > ----- > > This approach might work in most of the cases. However user thread > waiting for 3 sec is not a deterministic way to find if the balance > was started successfully in the kernel. IMO. Yes, that's right, it's the simplest thing to implement right now. > Instead can we use the balance start ioctl to spin a kthread > to run the actual balance that is __btrfs_balance(). With means > until call to __btrfs_balance() we shall use ioctl-thread and > to spin up kthread to run __btrfs_balance() and return the ioctl > thread with the interim status > (So for the --no-background user thread has to monitor the > balance status using the balance progress ioctl and return when > the status becomes completed and also it should call balance control > ioctl if the received sigint). > > We do use kthread for balance, if mount thread has to resume the > balance. so its a kind of extension to it. > > But in the view of the backward btrfs-progs compatibility (that is new > kernel with old progs) it looks like we need a new balance-ioctl > altogether, but the question is if its too much infrastructure changes, > which otherwise might have worked fairly well with a 3 sec delay? What > do you think? I think its a good idea to fix it in the right way. The balance ioctl could start a kthread, we don't need to do a new ioctl but just extend flags passed to BTRFS_IOC_BALANCE_V2. As the current --background option creates a userspace process, this is something we can't silently change to a kernel thread. So this will probably need a new option but otherwise I don't see any other problems. Reporting the status is done in the same way using the ioctl BTRFS_IOC_BALANCE_PROGRESS . The 3 second wait is not 100% reliable, we can potentially make it a bit more reliable if the timeout starts right before the other process starts the ioctl. To minimize effects of activity in the rest of the system. This could be done in a simple way by a pipe that signals from the child to the parent that the ioctl is going to be called next.
From: Marcos Paulo de Souza <mpdesouza@suse.com> The first patch removes the close/open operation of stderr, so we can receive errors of balance when starting in the background. The second patch waits up to three seconds after started the balance process, to check is some problem happened to the balance process. This is done only when the user issues the "balance start" in background mode. This was tested by issuing running "btrfs balance start --background --full-balance <path>", when the balance started, issue the same command again in the same terminal: # ./btrfs balance start --background --full-balance /mnt # ./btrfs balance start --background --full-balance /mnt ERROR: error during balancing '/mnt': Operation now in progress These two patches together fixes the issue 167[1]. Please review, Thanks. [1]: https://github.com/kdave/btrfs-progs/issues/167 Marcos Paulo de Souza (2): btrfs-progs: balance: Don't set stderr to /dev/null on balance_start btrfs-progs: balance: Verify EINPROGRESS on background balance cmds/balance.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)