From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 3DE7E81B37 for ; Wed, 18 Nov 2026 13:58:56 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AIDvhHW025975; Wed, 18 Nov 2026 16:57:44 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AIDvhHW025975 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="Sc7Z7RPi" Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AIDvYTF025951 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Wed, 18 Nov 2026 16:57:34 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AIDvYTF025951 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-48e00f3929bso1230564f8f.0 for ; Wed, 18 Nov 2026 05:57:34 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErHmSX18xlre3i0i4AQ7BxEoaaQ57D+k2nTFQtatcVzPvyhPzs5udsZFSEdJcqSMELF8iYwlzA==@openvz.org X-Gm-Message-State: APuU4Z8mYIlpUUPySuP6UZGW16yybUOwoAuCM/QIAlagVQHmAT1M1lHa uxiBpipBzHNfLCjMCTKkRZlH91Jsi2iJmx7luQlYwZ6WVIYMYhYbtn+IGv2flQSVn5GA3KxqENJ GQEsXwcBP/wgrjQ31uE+o21LbjbAn4s9CFqskWTpUtWyplntA6ocRNA== X-Gm-Gg: AZFdTZe6/QezCZ8skypE5TDWrdBU+PrsV0w6+uSpl0zcGsmHry2UNU4SdgPtUp2lHCb xuWbFQlYZMijsTTH0IIoXqOte+YD5gKXq6sbSk4wPVJbvYu1uKrgDryA0va68d80EC8zfDi+VEY f9TlB+7o3S6R2CZJLC4xQJK/5+GHIL2Xjq3hEuTSgfonNAHI4mBu8ch8IwWCVfvt7NPDwpOvowR KDBtQvoTUE+kTz8FCkxe3wJ+bJHLwAlM2KNvCwhh7Rpiomovp+i6lbxCrtYAC3W7rIL2Tvdg1Nw S4pwH/5XSwxT76kj6Y7yB1Lgm+WLCr1y2YmV0xq6BSt7yO30T+UG2ty5PGx17JtAqeMLA6dS4/V bHsIjRJsGxsUF8ogV3Y+3iQdfe6MFcU4= X-Received: by 2002:a05:6000:29cb:b0:48e:127a:c914 with SMTP id ffacd0b85a97d-4a372b3119fmr9483388f8f.5.1795010254208; Wed, 18 Nov 2026 05:57:34 -0800 (PST) X-Received: by 2002:a05:6000:29cb:b0:48e:127a:c914 with SMTP id ffacd0b85a97d-4a372b3119fmr9483350f8f.5.1795010253598; Wed, 18 Nov 2026 05:57:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795010253; cv=none; d=google.com; s=arc-20260327; b=PA6A7scDR2fnsSPjj3z0l4ovkXPqUTq/4Cu+34xe7x7O4ok4ankUqCmy9MBcscUhhb ZM4Z/HSBhqWBf56s1vB8KoTIfrAUzI2nh274F5lDvzw/Pd5X234v4gQ/Q5vClofFvyC8 kRRHzmuKpraUFu8ZQkHhmu88AWYZ3lhNRVnt5QNV8ZIK3egpFovLV/ocKvCZLbScrgFB DYG7ejWXPcAxlxCCOfVlxtfgIOGsrVUuw+AHoY1O7Bc2+gmP3Uu417yeWbW3Jp6PNUDj sIaDRSnYjBXYHiijjacvYjHk/TnRXJaWOXHAeH81S7rIUh0ywtvtHsS9S08eZlvG5gJG EfLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=ISK91I7UtKQI+nNNNTP1FboqDnzwIpnzkQyxXNlXhi8=; fh=ZnVB5BqLQwOrjngKsM/BdGGkHQvWunVG82yeReB8YoQ=; b=lKEJlVTBTgtqk6AMa/K3Bp95H8f3x79V2tyk1/iKg4jL+NIGZkFlZzNil1mszFLbdG XzCRrA3mmMZgjSeEpAblzWH22CXblSBhhmug3FB1LmnzUrqcX0diebNVJsJltxu8EsVr dN06qw8YVi1TByci7N6bphJ4BShpYQh7Cik+BBJBHZmKetKTbS+Z9XYbSURfvMCst7Qo g6zRIE2fXVgXNV7ASrfafF8FE9GiOh9xpFK6oXuoBzecn5xjzrjoXe/WmuNWyStUd/sQ 946pbHMJQZk8HZuAGJIifZDIp9FJp/FEgXhuR4va3Qt2s6QA4B1IlVs5cng9XNXP0tZ1 emSw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=Sc7Z7RPi; spf=pass (google.com: domain of vasileios.almpanis@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=vasileios.almpanis@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id ffacd0b85a97d-4a65a8723ebsi5153214f8f.406.2026.11.18.05.57.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 05:57:33 -0800 (PST) Received-SPF: pass (google.com: domain of vasileios.almpanis@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=Sc7Z7RPi; spf=pass (google.com: domain of vasileios.almpanis@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=vasileios.almpanis@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=Message-Id:Content-Type:MIME-Version:Subject:Date :From; bh=ISK91I7UtKQI+nNNNTP1FboqDnzwIpnzkQyxXNlXhi8=; b=Sc7Z7RPilLmyEiGtwQc S6Ny/vxFktiVeVZmxZc+6xOXlaI6qjyUsVnADw6zXaeVsME4GeBVmUZNdXd/N6e3WStE7XU4QtxFk N/BxX7bLIczw840VbDAQHf4nke6Rz+JQUotlSzbZicWVTIr/mDVCln4COKu2PMixRuSEWhBCCzmLt OQh40NHsnZv3hUrtYju7Eq7wKRXzjyFHUvtj1RcN0jFd+2xCAsL2sB0gj7cBMWA5+Ham6NGc1oj/Y uCxAaooojEQW6z1CkhHKqhFHGvqTJBKqCZ5dZQTidsh4m2irjUNnS7vw70i0AkjZBZd8pABm4Fe/m 8F5W3Cz186UWLCQ==; Received: from [130.117.225.5] (helo=dev010.ch-qa.vzint.dev) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1xTg5y-005hYm-36; Wed, 18 Nov 2026 14:57:32 +0100 From: Vasileios Almpanis Date: Wed, 18 Nov 2026 13:57:29 +0000 MIME-Version: 1.0 Message-Id: <20261118-vstor-153891-v2-3-e91753150b91@virtuozzo.com> References: <20261118-vstor-153891-v2-0-e91753150b91@virtuozzo.com> In-Reply-To: <20261118-vstor-153891-v2-0-e91753150b91@virtuozzo.com> To: Konstantin Khorenko X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1795010252; l=6646; i=vasileios.almpanis@virtuozzo.com; s=20260812; h=from:subject:message-id; bh=hVLTXbY9AQ/7b0cQocEOYZDiIZIAeK8TOsev2JGqNs4=; b=9UJmqv6EJwb8Xczfbb6Nm6FV5w2X0YmKuBf1bcmG7uql4ZqfCmegke9JdbrH5EsnQbfUEguMh vuloE+GXBFtCUpkzgWoiISFyoBSgMUpwVxscP+h1BGK85jsSJOmRp2X X-Developer-Key: i=vasileios.almpanis@virtuozzo.com; a=ed25519; pk=HhuHDXAcPva9A8zccWEMRsb36reu+y4IVbBjXKxNUjw= X-OZ-Fwd: true Cc: Den Lunev , devel@openvz.org Subject: [Devel] [PATCH hci-8.2 v2 3/3] dm/push_backup: stop the backup when the process that started it exits X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org When ploop-backup dies, the push_backup target does not notice it. The writes that wait for a backup stay postponed until the deadline timer fires. The timeout is a required argument of push_backup_start, and ploop-backup passes 60 seconds by default. During that time every writer to the device blocks, and so does every sync() on the host, because writeback waits for the postponed requests. We cannot simply lower the timeout, because a live ploop-backup can legitimately stall on IO for tens of seconds. Add an optional argument to push_backup_start: push_backup_start fail_on_process_exit With this argument the target watches the process that sent the message. To do that we add our own entry to the pid->wait_pidfd wait queue of its thread group. The kernel wakes up this queue when the process exits and when it is reaped. When the whole process is gone, the entry removes itself from the queue and queues the same work as the deadline timer. The exit of the main thread alone does not count while other threads of the process are still running. So when the backup process dies, the session expires in the same way as on the deadline. The postponed writes are resubmitted immediately, the target reports the session as expired and reads on the event fd return ESTALE. Because the target watches the sender, the message has to come from the backup process itself. If it is sent with "dmsetup message", the session expires as soon as dmsetup exits. We watch the process and not the event fd, because the fd is bound to the target and not to a backup session, see commit d723a1617e61 ("dm/push_backup: add event file descriptor interface"). Also a session that is driven by push_backup_read and push_backup_write has no fd at all. The watch is dropped on push_backup_stop, on the next push_backup_start and when the target is destroyed. Bump the target version to 1.2.0 so that userspace can check that the argument is supported. https://virtuozzo.atlassian.net/browse/VSTOR-153891 Feature: dm-backup: push backup target driver Suggested-by: Andrey Zhadchenko Reviewed-by: Denis V. Lunev Signed-off-by: Vasileios Almpanis --- drivers/md/dm-push-backup.c | 61 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/drivers/md/dm-push-backup.c b/drivers/md/dm-push-backup.c index 4c6fb97bbb5e..745ed28fd074 100644 --- a/drivers/md/dm-push-backup.c +++ b/drivers/md/dm-push-backup.c @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include @@ -75,6 +77,9 @@ struct push_backup { struct work_struct worker; struct rw_semaphore ctl_rwsem; + + struct pid *watched_pid; + struct wait_queue_entry pid_wait; }; static void pb_release(struct kref *ref) @@ -271,6 +276,48 @@ static void pb_timer_func(struct timer_list *timer) spin_unlock_irqrestore(&pb->lock, flags); } +static bool pb_process_exited(struct pid *pid) +{ + struct task_struct *task; + + guard(rcu)(); + task = pid_task(pid, PIDTYPE_TGID); + return !task || (task->exit_state && thread_group_empty(task)); +} + +/* + * Called under tasklist_lock with irqs disabled when the watched process + * exits or is reaped. If the whole process is gone, stop watching it and + * expire the backup in the same way as the deadline timer does. + */ +static int pb_pid_wake(struct wait_queue_entry *wait, unsigned int mode, + int flags, void *key) +{ + struct push_backup *pb = container_of(wait, struct push_backup, pid_wait); + + if (pb_process_exited(pb->watched_pid)) { + list_del_init(&wait->entry); + queue_work(pb->wq, &pb->worker); + } + return 0; +} + +static void pb_watch_pid(struct push_backup *pb) +{ + pb->watched_pid = get_task_pid(current, PIDTYPE_TGID); + add_wait_queue(&pb->watched_pid->wait_pidfd, &pb->pid_wait); +} + +static void pb_unwatch_pid(struct push_backup *pb) +{ + if (!pb->watched_pid) + return; + remove_wait_queue(&pb->watched_pid->wait_pidfd, &pb->pid_wait); + put_pid(pb->watched_pid); + pb->watched_pid = NULL; + flush_work(&pb->worker); +} + static int postpone_if_required_for_backup(struct push_backup *pb, struct request *rq) { @@ -406,6 +453,7 @@ static int push_backup_start(struct push_backup *pb, u64 timeout, return -EEXIST; if (timeout == 0 || timeout >= 60UL * 60 * 5) return -EINVAL; + pb_unwatch_pid(pb); return setup_pb(pb, mask, timeout); } @@ -417,6 +465,7 @@ static int push_backup_stop(struct push_backup *pb, if (!pb->map) return -EBADF; cleanup_backup(pb); + pb_unwatch_pid(pb); timer_delete_sync(&pb->deadline_timer); flush_workqueue(pb->wq); @@ -725,14 +774,18 @@ static int pb_message(struct dm_target *ti, unsigned int argc, char **argv, ret = -EINVAL; if (!strcmp(argv[0], "push_backup_start")) { - if (argc < 2 || argc > 3) + if (argc < 2 || argc > 4) goto unlock; if (kstrtou64(argv[1], 10, &val) < 0) goto unlock; val2 = 0; - if (argc == 3 && kstrtou64(argv[2], 10, &val2) < 0) + if (argc >= 3 && kstrtou64(argv[2], 10, &val2) < 0) + goto unlock; + if (argc == 4 && strcmp(argv[3], "fail_on_process_exit")) goto unlock; ret = push_backup_start(pb, val, (void *)val2); + if (!ret && argc == 4) + pb_watch_pid(pb); } else if (!strcmp(argv[0], "push_backup_stop")) { ret = push_backup_stop(pb, result, maxlen); } else if (!strcmp(argv[0], "push_backup_read")) { @@ -777,6 +830,7 @@ static void pb_destroy(struct push_backup *pb) wake_up_interruptible(&pb->waitq); + pb_unwatch_pid(pb); timer_shutdown_sync(&pb->deadline_timer); if (pb->wq) destroy_workqueue(pb->wq); @@ -818,6 +872,7 @@ static int pb_ctr(struct dm_target *ti, unsigned int argc, char **argv) timer_setup(&pb->deadline_timer, pb_timer_func, 0); init_waitqueue_head(&pb->waitq); INIT_WORK(&pb->worker, do_pb_work); + init_waitqueue_func_entry(&pb->pid_wait, pb_pid_wake); pb->pbio_pool = mempool_create_slab_pool(PUSH_BACKUP_POOL_SIZE, pbio_cache); @@ -920,7 +975,7 @@ static loff_t pb_llseek_hole(struct dm_target *ti, loff_t offset, static struct target_type pb_target = { .name = "push_backup", - .version = {1, 1, 0}, + .version = {1, 2, 0}, .features = DM_TARGET_SINGLETON, .module = THIS_MODULE, .ctr = pb_ctr, -- 2.43.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel