Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1289877pxj; Wed, 19 May 2021 02:39:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy6MXwAc0UL9s7lqz73qmVJ7qd2H5lF+SJWBj8T6uuhR1kSw3CXRdZxZpXzqBRSk4CDgcuw X-Received: by 2002:a92:d6c9:: with SMTP id z9mr9421768ilp.133.1621417147618; Wed, 19 May 2021 02:39:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621417147; cv=none; d=google.com; s=arc-20160816; b=SeNPKKKVTgESQpgIrLzVO/VclaB9EW1jsKNKN90RKu7htHHBGgvK115mOUmctltDJU is32iZY8mj3tNp5Li6waHnfnNrlbAtGtr+Wc8U46+8ByR0qsj3N8hJC0y4wDoUn/DP1t kx2v6+z3etYtQfv/7QqpMLYkdrJDT4aQzynmrliCRFLghMSHemQnYcMTzVA7t/bbKL6G fXn1Z1QUk0M9BCqkDOfbmkN0P61cy7+rl1bYMlhUIDCjObswWBgfbUTJCVIVi+lRO5q0 HJjFELSkZek1haV0pszPjKhxM0wByVJW7on2F+JChvqHG4nxJxgAsuMHhuSNhHZPslf+ PW8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=xCtpJl5wAKagxb9hM9Z4VWmYK67Am2vQEsG/WsS00BA=; b=en4y11OQqLd0ecLc5/HGdudyVi1EPhGd/xN0e81u/nLKop3RW/oLxCXNRSd8tQVOIJ xke+LiW4h/l2xGJXAs4fDH5f9MsePvA3lmZjioJvDC6Rfd/nDXTbSkSVnMGCstA2CpvQ V1IKRQiC9+VhUP8zY8YPPe9WJPwgcoQQMM1cYNcm3B1RVpOIHcBTuf7BZ70INA0XIwP3 SzkKXLd67M6Coq1fwEfJUiLI7JYAKEW971IwTyl6BeroLuFjEhzTrgUMxqCGSbQvH724 KOwLH78WoUMeSS8bdJObJQdVsKplf+IEhCBsrCVYv80kuQJ55Gf2tZB4W6Lj87DO/h9s /bOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IKbqof1A; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j2si10711928jak.119.2021.05.19.02.38.54; Wed, 19 May 2021 02:39:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IKbqof1A; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239316AbhERAbR (ORCPT + 99 others); Mon, 17 May 2021 20:31:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:36628 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233718AbhERAbR (ORCPT ); Mon, 17 May 2021 20:31:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621297799; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=xCtpJl5wAKagxb9hM9Z4VWmYK67Am2vQEsG/WsS00BA=; b=IKbqof1Aj/Gb4VJBGKA5WeWGiL4XTJ0YE4iDcIKwHjtB3Sr1pdwYjPX3ZSylLLf2ThpJVH z0qM2kcc/+EflkVU6VtBDmMckv/i0q9f7u2DeV9AHwFyisaU7WWz2YFenYgaSEJxjypkZo zUBSXf56+c5NnFIOXI9jfxWJVxiLXkY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-299-Kv5nR3XBNRWIwn1qWCLM3g-1; Mon, 17 May 2021 20:29:58 -0400 X-MC-Unique: Kv5nR3XBNRWIwn1qWCLM3g-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A92601A8A61; Tue, 18 May 2021 00:29:56 +0000 (UTC) Received: from T590 (ovpn-12-90.pek2.redhat.com [10.72.12.90]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0F99860C25; Tue, 18 May 2021 00:29:45 +0000 (UTC) Date: Tue, 18 May 2021 08:29:40 +0800 From: Ming Lei To: Prasanna Kumar Kalever Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, nbd@other.debian.org, josef@toxicpanda.com, axboe@kernel.dk, idryomov@redhat.com, xiubli@redhat.com, Matteo Croce Subject: Re: [PATCH] nbd: provide a way for userspace processes to identify device backends Message-ID: References: <20210429102828.31248-1-prasanna.kalever@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210429102828.31248-1-prasanna.kalever@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Prasanna, On Thu, Apr 29, 2021 at 03:58:28PM +0530, Prasanna Kumar Kalever wrote: > Problem: > On reconfigure of device, there is no way to defend if the backend > storage is matching with the initial backend storage. > > Say, if an initial connect request for backend "pool1/image1" got > mapped to /dev/nbd0 and the userspace process is terminated. A next > reconfigure request within NBD_ATTR_DEAD_CONN_TIMEOUT is allowed to > use /dev/nbd0 for a different backend "pool1/image2" > > For example, an operation like below could be dangerous: Can you explain a bit why it is dangerous? > > $ sudo rbd-nbd map --try-netlink rbd-pool/ext4-image > /dev/nbd0 > $ sudo blkid /dev/nbd0 > /dev/nbd0: UUID="bfc444b4-64b1-418f-8b36-6e0d170cfc04" TYPE="ext4" > $ sudo pkill -9 rbd-nbd > $ sudo rbd-nbd attach --try-netlink --device /dev/nbd0 rbd-pool/xfs-image > /dev/nbd0 > $ sudo blkid /dev/nbd0 > /dev/nbd0: UUID="d29bf343-6570-4069-a9ea-2fa156ced908" TYPE="xfs" > > Solution: > Provide a way for userspace processes to keep some metadata to identify > between the device and the backend, so that when a reconfigure request is > made, we can compare and avoid such dangerous operations. > > With this solution, as part of the initial connect request, backend > path can be stored in the sysfs per device config, so that on a reconfigure > request it's easy to check if the backend path matches with the initial > connect backend path. > > Please note, ioctl interface to nbd will not have these changes, as there > won't be any reconfigure. BTW, loop has similar issue, and patch of 'block: add a sequence number to disks' is added for addressing this issue, what do you think of that generic approach wrt. this nbd's issue? such as used the exposed sysfs sequence number for addressing this issue? https://lore.kernel.org/linux-block/YH81n34d2G3C4Re+@gardel-login/#r Thanks, Ming