From patchwork Thu Feb 22 07:24:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13566784 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 94142175A4 for ; Thu, 22 Feb 2024 07:24:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708586665; cv=none; b=Hj2r7CaJr6mdBSD2axtsOyLFA6n4TBu1PhoHaXjbecYE7bTr7dqErrPsNfNwelLtHpQZg3VU7umiAsMVJVedKgeegDjv/nWdQMVucj+wn3phPxodBYWeDDd0iKmoOoW2nqP6Ns/RmaI69VkoTx+10KB/eXtmrDBX7Rg5svmFFdk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708586665; c=relaxed/simple; bh=htyvJj+g9bTQyuHGt7YYBD4/zUbsHS36ItWMplXpXf0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kR61NspYszamPHEBay5AYO4ax1wPf9JAfILjVHbjOZIuEryhLFVRBV02n/jH3VtIf+FeP5XVQTv1N+KL5H1cD7KO8evZHQFBF7DiiRkRT0D8yggqDRV1H93UKf/+0e9LzFDYdQohIFqkvxz8huGVWiDxkHX/hoVs4+JlRXS62HE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=vFn9qwWE; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="vFn9qwWE" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=iZVt+4PHBEup3fys/3++8LkDhk2PlaRb6Zd/R2NR/Ws=; b=vFn9qwWEpaxHLnL3TQErmJlZ+r X9rDaFlotZde6HwNYWfcuJBdUZ0AQ9iMsFqDKTIplmjpz4UTI8m0qStBnIFhZ3VFzWDHTZAMzcLHM EQ9CK/bWyzmfObh1WuWUOudXQzqTJ1U6qx/nnpScl042sCea508EwG/pUifHyhMEQG2lir5z7b9pj aZBBS+05iB8RA542BetS6kgezoNDikV3vgHBA2FEMbKU/RQaqtlapYlvQ8YxIH1TscnAiOc7ICx6o cRPoowVy1wPauhNy5QXet5NCnGfZLMuGeOkOYyWKzDh6TIyGvHCMrnEv6uJ0FefRCrCPhtffH7fDV Y+j3HY8A==; Received: from [2001:4bb8:19a:62b2:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rd3RN-00000003ncd-2Usl; Thu, 22 Feb 2024 07:24:21 +0000 From: Christoph Hellwig To: Richard Weinberger , Anton Ivanov , Johannes Berg , Jens Axboe Cc: linux-um@lists.infradead.org, linux-block@vger.kernel.org Subject: [PATCH 1/7] ubd: remove the ubd_gendisk array Date: Thu, 22 Feb 2024 08:24:11 +0100 Message-Id: <20240222072417.3773131-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240222072417.3773131-1-hch@lst.de> References: <20240222072417.3773131-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html And add a disk pointer to the ubd structure instead to keep all the per-device information together. Signed-off-by: Christoph Hellwig Reviewed-by: Richard Weinberger --- arch/um/drivers/ubd_kern.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c index 48e11f073551b4..b203ebb1785125 100644 --- a/arch/um/drivers/ubd_kern.c +++ b/arch/um/drivers/ubd_kern.c @@ -125,9 +125,6 @@ static const struct block_device_operations ubd_blops = { .getgeo = ubd_getgeo, }; -/* Protected by ubd_lock */ -static struct gendisk *ubd_gendisk[MAX_DEV]; - #ifdef CONFIG_BLK_DEV_UBD_SYNC #define OPEN_FLAGS ((struct openflags) { .r = 1, .w = 1, .s = 1, .c = 0, \ .cl = 1 }) @@ -165,6 +162,7 @@ struct ubd { unsigned no_trim:1; struct cow cow; struct platform_device pdev; + struct gendisk *disk; struct request_queue *queue; struct blk_mq_tag_set tag_set; spinlock_t lock; @@ -922,7 +920,6 @@ static int ubd_add(int n, char **error_out) if (err) goto out_cleanup_disk; - ubd_gendisk[n] = disk; return 0; out_cleanup_disk: @@ -1014,7 +1011,6 @@ static int ubd_id(char **str, int *start_out, int *end_out) static int ubd_remove(int n, char **error_out) { - struct gendisk *disk = ubd_gendisk[n]; struct ubd *ubd_dev; int err = -ENODEV; @@ -1030,10 +1026,9 @@ static int ubd_remove(int n, char **error_out) if(ubd_dev->count > 0) goto out; - ubd_gendisk[n] = NULL; - if(disk != NULL){ - del_gendisk(disk); - put_disk(disk); + if (ubd_dev->disk) { + del_gendisk(ubd_dev->disk); + put_disk(ubd_dev->disk); } err = 0; From patchwork Thu Feb 22 07:24:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13566785 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64FF31799C for ; Thu, 22 Feb 2024 07:24:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708586668; cv=none; b=fm5HXe6JqU8hobyctTZCifOSNW/4S9KQRzMT8QbkY3MD9uACKwWTg33As7b5BtzKfftY6K95J0X9HWbpoE1dYGPa3wxj+7+LqfoAYMB1JrtwNIf+AnG7XhmSswXUO7P8o+jYOHXNGraIvr72w7sbM6YvvN4al+BP014vv/geZXg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708586668; c=relaxed/simple; bh=vb9g5hXZqbWYnhfJqcSYR3cl58PvqYkQbZA21N4y1oI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dZ/QL0JfJfy1JIF9WozyoGHpkBz5rWpKaZ+TDAKZor5FFgiOuU1aRgw2djR8MpNdz99yGXZJ4Fg55lTffGQKzwiPHL/FZZGjha7FyZ4zaUK2DzCMuEmtTm4gOYhXAdocX5xPhK1NwfeSOcFAaAGNdhOOOyDskV1zfSFvx4K02Z4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=HbIiGWGr; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="HbIiGWGr" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=cTy5ByRm6yl9copb54tFACKFS8S5cRwyQfPP7IgncdE=; b=HbIiGWGrhljmpDEC6OzKVfdVyd V+emT/QF9FFj13OIKzJc3PNTiqHMsSNadL52I7Xk1qIayH+2sma1aukGXuA+Do6+GWrNImq0nX0pn 76ienUdw2AZjkxTNjZLfZSypLjIg8m28E7lDrMDgzdpzi3+Lmyfmu7Jfw5+Z75DhxWISkQi0GvdRk qr7g4m9R1jaR8H4KvdzSZeFHckdlxWY8kfUcpbBF2GAWGG/6Zprx9KpHXBLwy2SJvoIF4A4/8+poE qu7MMi+RQXR4o6GtZyi/7OVrcnZMLrNWOO1kd/FVUWzaMH+0br5RVC5SPc2eLOEViG39b1be1+8Ny 85ChpUjQ==; Received: from [2001:4bb8:19a:62b2:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rd3RQ-00000003nd1-0gxi; Thu, 22 Feb 2024 07:24:24 +0000 From: Christoph Hellwig To: Richard Weinberger , Anton Ivanov , Johannes Berg , Jens Axboe Cc: linux-um@lists.infradead.org, linux-block@vger.kernel.org Subject: [PATCH 2/7] ubd: remove ubd_disk_register Date: Thu, 22 Feb 2024 08:24:12 +0100 Message-Id: <20240222072417.3773131-3-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240222072417.3773131-1-hch@lst.de> References: <20240222072417.3773131-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Fold it into the only caller to remove lots of references to the global ubd_devs array. Signed-off-by: Christoph Hellwig Reviewed-by: Richard Weinberger --- arch/um/drivers/ubd_kern.c | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c index b203ebb1785125..ef05157acd6b02 100644 --- a/arch/um/drivers/ubd_kern.c +++ b/arch/um/drivers/ubd_kern.c @@ -849,27 +849,6 @@ static const struct attribute_group *ubd_attr_groups[] = { NULL, }; -static int ubd_disk_register(int major, u64 size, int unit, - struct gendisk *disk) -{ - disk->major = major; - disk->first_minor = unit << UBD_SHIFT; - disk->minors = 1 << UBD_SHIFT; - disk->fops = &ubd_blops; - set_capacity(disk, size / 512); - sprintf(disk->disk_name, "ubd%c", 'a' + unit); - - ubd_devs[unit].pdev.id = unit; - ubd_devs[unit].pdev.name = DRIVER_NAME; - ubd_devs[unit].pdev.dev.release = ubd_device_release; - dev_set_drvdata(&ubd_devs[unit].pdev.dev, &ubd_devs[unit]); - platform_device_register(&ubd_devs[unit].pdev); - - disk->private_data = &ubd_devs[unit]; - disk->queue = ubd_devs[unit].queue; - return device_add_disk(&ubd_devs[unit].pdev.dev, disk, ubd_attr_groups); -} - #define ROUND_BLOCK(n) ((n + (SECTOR_SIZE - 1)) & (-SECTOR_SIZE)) static const struct blk_mq_ops ubd_mq_ops = { @@ -916,7 +895,21 @@ static int ubd_add(int n, char **error_out) ubd_dev->queue = disk->queue; blk_queue_write_cache(ubd_dev->queue, true, false); - err = ubd_disk_register(UBD_MAJOR, ubd_dev->size, n, disk); + disk->major = UBD_MAJOR; + disk->first_minor = n << UBD_SHIFT; + disk->minors = 1 << UBD_SHIFT; + disk->fops = &ubd_blops; + set_capacity(disk, ubd_dev->size / 512); + sprintf(disk->disk_name, "ubd%c", 'a' + n); + disk->private_data = ubd_dev; + + ubd_dev->pdev.id = n; + ubd_dev->pdev.name = DRIVER_NAME; + ubd_dev->pdev.dev.release = ubd_device_release; + dev_set_drvdata(&ubd_dev->pdev.dev, ubd_dev); + platform_device_register(&ubd_dev->pdev); + + err = device_add_disk(&ubd_dev->pdev.dev, disk, ubd_attr_groups); if (err) goto out_cleanup_disk; From patchwork Thu Feb 22 07:24:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13566786 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 61C111799F for ; Thu, 22 Feb 2024 07:24:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708586669; cv=none; b=dMEb2T0jQRV/JjjHX5vY4Dh9Whd8Hr2ylLeuipN2yNxRGpxjc8/putD2p0bBtKrWGxn/YOrRovGjshXdm3k5KcOlILTNW5kB+Vfqs50Fkfxpn6BQPwTFXHSjpWlaMO9TK06UwOdzSIhP0Htlp9DbLlDkNctrxJJL71zcgwPlpQ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708586669; c=relaxed/simple; bh=bp7GYBlBL2or4dRhmeORwvc4sNgNyBajh9DAOA1FWI0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fZHwdVE3pYy0bssLdnRaLo8QzqN4uDWY7A2epago34wqzIvnT4M1xPHea7O7ZWrZh/3Pm2bVxfqfiYfdtla/A7KKfJXMyYqXm/QpvMyHMzI6NGLEqi2otX2rt4a26hZV7lfcK0gIGRW7Hkpc156ih2u+hGFkWoqtO1uKUoMkkM8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=3/KfwHSR; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="3/KfwHSR" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=2BFULQQpf3659ifgG7eJf7nI2YTQWRMkjSUtn4KfBjI=; b=3/KfwHSR7UwxuBW8HMjTrLccLS qA7vCTsQcSgNv2Ty1zJ8u+kPFYQCp3Bi4uoDcUMMdtQr+8ohXqsVEbyKC3NBiaA/mx8Mot3/SF6p6 bqvbyLpeqUpNbAk5iPYyO/g5ZP8DL0W212PCVc7uks8re0fTMwoY3k3S/fw1abkhJgif906CVxr1v tPm9pYjOCVTe+qKOoqGtJ03ZK+utPTSpIsQoJuCNYtnrKfPErEBZ/NK1dBMu54xqISkEMI6qUGD/p RCIbWoXMJmtpcR+Ba5ZinITjrhUWQU+9dQLssVhAWeq/JT7TT5mKYW4oeq1Cf+hbkNRDxVv37hp21 B2MKcjVg==; Received: from [2001:4bb8:19a:62b2:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rd3RS-00000003ndp-3S4s; Thu, 22 Feb 2024 07:24:27 +0000 From: Christoph Hellwig To: Richard Weinberger , Anton Ivanov , Johannes Berg , Jens Axboe Cc: linux-um@lists.infradead.org, linux-block@vger.kernel.org Subject: [PATCH 3/7] ubd: move setting the nonrot flag to ubd_add Date: Thu, 22 Feb 2024 08:24:13 +0100 Message-Id: <20240222072417.3773131-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240222072417.3773131-1-hch@lst.de> References: <20240222072417.3773131-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html No reason to delay this until open time. Signed-off-by: Christoph Hellwig Reviewed-by: Richard Weinberger --- arch/um/drivers/ubd_kern.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c index ef05157acd6b02..9dcf41f7d49606 100644 --- a/arch/um/drivers/ubd_kern.c +++ b/arch/um/drivers/ubd_kern.c @@ -799,7 +799,6 @@ static int ubd_open_dev(struct ubd *ubd_dev) blk_queue_max_discard_sectors(ubd_dev->queue, UBD_MAX_REQUEST); blk_queue_max_write_zeroes_sectors(ubd_dev->queue, UBD_MAX_REQUEST); } - blk_queue_flag_set(QUEUE_FLAG_NONROT, ubd_dev->queue); return 0; error: os_close_file(ubd_dev->fd); @@ -894,6 +893,7 @@ static int ubd_add(int n, char **error_out) } ubd_dev->queue = disk->queue; + blk_queue_flag_set(QUEUE_FLAG_NONROT, disk->queue); blk_queue_write_cache(ubd_dev->queue, true, false); disk->major = UBD_MAJOR; disk->first_minor = n << UBD_SHIFT; From patchwork Thu Feb 22 07:24:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13566787 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C4F8B1799F for ; Thu, 22 Feb 2024 07:24:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708586672; cv=none; b=ncsEJdY2cZ/wVkfxf1V0Ox626AX3ndDrHY0dMhfIAarIKPNRgIQHx4tPyEvORQTBdIlGDgI3ciOv5Jq9PJq2/iO6M6O4ofiR4A3OFS+hwHXtkVldjJcGNGUqmoXVywKY9g4gaiqCJxlIbuhkJuYBZQdZtDkOGJJsXufNg9wQZfk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708586672; c=relaxed/simple; bh=ZsJemB2Am7PLEDU4QmQys8AqWXEaYW5k4r1EZGTk3W0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Dkiy/BjaQaQNmceW5WxFTmGVqX6qEa/QBSvQvUoWb+IL8oQlXhAB3VI3PHE3h+x2qbf4K7k5SrBKL9lpr4aT7htp3auy70791MqieJKuVgHFBvgLQFc3dP/W8FsVUnis/adOOAYE/e31DHrkaY0HUAs6h2coJFK6NR/bU98UFws= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=Eag9BblR; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Eag9BblR" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=XOrf8aRVfOLyUlEU9mfD8SHhHCuj9KCbbzXY0gtM8to=; b=Eag9BblRnTk83NT+8JgmaNd0LD MB5fC5BGQQUAm7yz4fSziww73vtO4ZRUC0VIH1eQgUzV3XyudjSEd35DPRJjMyLV+8BSEBV0CSjcx jrliV6bffM900tnL6ANHhhTyePN86uIGI5nzulLUEH5DFp/HPAoeXfZdGPK+gqLRy8PYT3l8aFfSI PWS/yjh3RT/EOzJyMowoNAKv7OBsoG3rn8/UWSObkBDJR9hhYD8Aou/Whkia1/nvl6b11cEvFSPk6 mZZ6PfQI7eHjfWN1cK7Sdom1Z3fKxRDAauipfe/lEMAUm+tWNyw9lC1UIF39QNUl+I8oVDH+U1YWL C6I+0A/A==; Received: from [2001:4bb8:19a:62b2:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rd3RV-00000003nfE-1eoJ; Thu, 22 Feb 2024 07:24:29 +0000 From: Christoph Hellwig To: Richard Weinberger , Anton Ivanov , Johannes Berg , Jens Axboe Cc: linux-um@lists.infradead.org, linux-block@vger.kernel.org Subject: [PATCH 4/7] ubd: move setting the variable queue limits to ubd_add Date: Thu, 22 Feb 2024 08:24:14 +0100 Message-Id: <20240222072417.3773131-5-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240222072417.3773131-1-hch@lst.de> References: <20240222072417.3773131-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html No reason to delay this until open time. Signed-off-by: Christoph Hellwig Reviewed-by: Richard Weinberger --- arch/um/drivers/ubd_kern.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c index 9dcf41f7d49606..26bc8306356263 100644 --- a/arch/um/drivers/ubd_kern.c +++ b/arch/um/drivers/ubd_kern.c @@ -772,8 +772,6 @@ static int ubd_open_dev(struct ubd *ubd_dev) ubd_dev->fd = fd; if(ubd_dev->cow.file != NULL){ - blk_queue_max_hw_sectors(ubd_dev->queue, 8 * sizeof(long)); - err = -ENOMEM; ubd_dev->cow.bitmap = vmalloc(ubd_dev->cow.bitmap_len); if(ubd_dev->cow.bitmap == NULL){ @@ -795,10 +793,6 @@ static int ubd_open_dev(struct ubd *ubd_dev) if(err < 0) goto error; ubd_dev->cow.fd = err; } - if (ubd_dev->no_trim == 0) { - blk_queue_max_discard_sectors(ubd_dev->queue, UBD_MAX_REQUEST); - blk_queue_max_write_zeroes_sectors(ubd_dev->queue, UBD_MAX_REQUEST); - } return 0; error: os_close_file(ubd_dev->fd); @@ -867,6 +861,13 @@ static int ubd_add(int n, char **error_out) if(ubd_dev->file == NULL) goto out; + if (ubd_dev->cow.file) + lim.max_hw_sectors = 8 * sizeof(long); + if (!ubd_dev->no_trim) { + lim.max_hw_discard_sectors = UBD_MAX_REQUEST; + lim.max_write_zeroes_sectors = UBD_MAX_REQUEST; + } + err = ubd_file_size(ubd_dev, &ubd_dev->size); if(err < 0){ *error_out = "Couldn't determine size of device's file"; From patchwork Thu Feb 22 07:24:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13566788 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B9E917988 for ; Thu, 22 Feb 2024 07:24:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708586674; cv=none; b=t3uK/+L3bBtoRS5CCCp09oPFHkx+xowgbLjeIrj5lPMZV3Yre5W3VoQJ0gv0uAcI2YXKl36Sahxq/nyyzGIbD8e3FQB5mie6ruhRbp1aYD2u/1ZcWIdGqvOLTvO/ihjrbsoGjBpMSg/17GsXGe13OTZARiUQua8gA8oYsQqIDcQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708586674; c=relaxed/simple; bh=xtAx8cWP72AJuDwX5dfWdD60bPkyuO57428kgFzM/xw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ulLpheZHzsNpFs1q/uju6H6ORnJ/out+VE/ijTVfPAlPncTxa7wo6Hx2pIrm2HTKrJumPIwH0LJN7YXstlUjpKZ621vwSdnc4FOGP4KRlrTtaiCKthNF4lgsVZ2pKSexj1NvGdV2oJpCkgbIhoXEU5lb3ayY+yQQP6O3kS2MKEg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=iDw57dsC; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="iDw57dsC" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=rSTF8EhkpxTeqhstKIyynLGq4fa8o7QHCgP9WngjV84=; b=iDw57dsCp+CcU/y95KaxGg4bEM DE6Dmhigd8MGFVx5s8UHtQNNHc97+JeMOqINLaRKtlRDVm4k+8LYH2hZC/Mn2GI+d6uy/03mx4eN3 L4JncjhapPO8VvQPBt11219fLFO8Uz2pr1EiUMEMvxEtgDgddQLVlOKi/ENDgmcfFpuWn3dyxfyu/ IQ+VEOcQASlQ0rrQHJMJTrUCJvY6RY/dQJx8IeJiTILBdL7McQraRz2TGjtMnuA870gl5nUPu7r/i qZbTOVvfn3tKtLi/UimuK3o6t2uOE2H/4NqENXvDAKU7KAa9ct0RcT4FVlSPTPmO5CREC9aG2Adyb Wz4dmRYg==; Received: from [2001:4bb8:19a:62b2:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rd3RX-00000003nfv-4465; Thu, 22 Feb 2024 07:24:32 +0000 From: Christoph Hellwig To: Richard Weinberger , Anton Ivanov , Johannes Berg , Jens Axboe Cc: linux-um@lists.infradead.org, linux-block@vger.kernel.org Subject: [PATCH 5/7] ubd: move set_disk_ro to ubd_add Date: Thu, 22 Feb 2024 08:24:15 +0100 Message-Id: <20240222072417.3773131-6-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240222072417.3773131-1-hch@lst.de> References: <20240222072417.3773131-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html No need to delay this until open time. Signed-off-by: Christoph Hellwig Reviewed-by: Richard Weinberger --- arch/um/drivers/ubd_kern.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c index 26bc8306356263..c5d32e75426366 100644 --- a/arch/um/drivers/ubd_kern.c +++ b/arch/um/drivers/ubd_kern.c @@ -903,6 +903,7 @@ static int ubd_add(int n, char **error_out) set_capacity(disk, ubd_dev->size / 512); sprintf(disk->disk_name, "ubd%c", 'a' + n); disk->private_data = ubd_dev; + set_disk_ro(disk, !ubd_dev->openflags.w); ubd_dev->pdev.id = n; ubd_dev->pdev.name = DRIVER_NAME; @@ -1159,7 +1160,6 @@ static int ubd_open(struct gendisk *disk, blk_mode_t mode) } } ubd_dev->count++; - set_disk_ro(disk, !ubd_dev->openflags.w); out: mutex_unlock(&ubd_mutex); return err; From patchwork Thu Feb 22 07:24:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13566789 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B0E317988 for ; Thu, 22 Feb 2024 07:24:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708586677; cv=none; b=ZekjA7RvpOc0HmxZVMRRPPWEDGX1LCJxBFcPadiNEGCsCNEJiODnV1q9Ni/KvR7RJi2fTol8A54sKIksh3aMGGvEdEWuiK9tZRDXk8XksOjMg2nJOKyXh0Bp+XavolVlxkYQsF/1SfMFhcBnu5OB78B1nzp9Jmqfcxd/GjP0YJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708586677; c=relaxed/simple; bh=JyRp/OahnGgPHjxodDKgy3d0/tKem2XxDYNixBXcIeM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RPe2k5qlbFsQzUUIkuCJ/OwcIITH+cxX+a/owyXboFIPzp2fzu5WpAKCJJ0e223Qe07KUJ24jvt3Gyr4mb6yJ6FfzV6Nv1fH4Eavcw8ZzT2xicegJ+Hjq+d4/W/BqXwuIKqNxa4lIFFM1+6zaNi9zFKh33gc6vkvgRk7NFhzK60= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=VEAmIdFv; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="VEAmIdFv" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=g/2GmS4AXLXXjlfuzEY4M+H/g1Vi8otqWk2R/DkaXmE=; b=VEAmIdFvHIObdHoyFHLq6Tqj3r i3mZ8eu8VLsb2bkNXK29+np+SjT2qXOP2HWbPC+6pV3nG5HdiRj1oryU7/fA/SOdg2cxYoWCqQtft 3jvkBW01nYDUP2lBwp3kOLxK1DtqTNatyswDGheIB+KOWJ39i6LwM5bpFwj9OiFFRHY4kN1rMHbj2 x6+ACBJeIwTIr93DJxDbfY+Y25hO+fn5G6GS/aDrGoLD47tKI18OdPY0IwNTj/Rnnfo8IezMjpaiu q0Q7tvHRQHimK8NyJS2ebgSAhB8JHyAfJPBeNk9uNt737/vfYrJGB9dJIE3hwqxYc/UnS53H5Bfig QsHcR62A==; Received: from [2001:4bb8:19a:62b2:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rd3Ra-00000003nhe-2Cdb; Thu, 22 Feb 2024 07:24:34 +0000 From: Christoph Hellwig To: Richard Weinberger , Anton Ivanov , Johannes Berg , Jens Axboe Cc: linux-um@lists.infradead.org, linux-block@vger.kernel.org Subject: [PATCH 6/7] ubd: remove the queue pointer in struct ubd Date: Thu, 22 Feb 2024 08:24:16 +0100 Message-Id: <20240222072417.3773131-7-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240222072417.3773131-1-hch@lst.de> References: <20240222072417.3773131-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html No need for it now, everything goes through the gendisk. Signed-off-by: Christoph Hellwig Reviewed-by: Richard Weinberger --- arch/um/drivers/ubd_kern.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c index c5d32e75426366..9bf1d6a88bae59 100644 --- a/arch/um/drivers/ubd_kern.c +++ b/arch/um/drivers/ubd_kern.c @@ -163,7 +163,6 @@ struct ubd { struct cow cow; struct platform_device pdev; struct gendisk *disk; - struct request_queue *queue; struct blk_mq_tag_set tag_set; spinlock_t lock; }; @@ -892,10 +891,9 @@ static int ubd_add(int n, char **error_out) err = PTR_ERR(disk); goto out_cleanup_tags; } - ubd_dev->queue = disk->queue; blk_queue_flag_set(QUEUE_FLAG_NONROT, disk->queue); - blk_queue_write_cache(ubd_dev->queue, true, false); + blk_queue_write_cache(disk->queue, true, false); disk->major = UBD_MAJOR; disk->first_minor = n << UBD_SHIFT; disk->minors = 1 << UBD_SHIFT; From patchwork Thu Feb 22 07:24:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13566790 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1AAD17988 for ; Thu, 22 Feb 2024 07:24:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708586680; cv=none; b=GiPMEjx1Pi/92aBhgWegecbHnDHjU8lEIUQxVtxDLJRp/CXFVRUjMJnRDRv6BdtMtJwVqPGcvELszUm7snGmO++DqZjhLg8xEAdWghWEnyMrhU0b0yTnCyirrCaJHnkWnos3aVWPoEauSS5wDV0I8aLMz/djVzsurPjcalEu8Uw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708586680; c=relaxed/simple; bh=P5RAyGVnbnwb7D7D4vkKFGL+E50ZuLdaNaJ7mUqDac0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pMK/odSwzVhPe0LVVzLy1FwGxQ04cjrMePllEABaCsEhVQHHfS+hMfWg2GN3RV284LmIGiXaWLA81e86Vk8svcFi6dVApwJeoUHI6Xsdd5kVCgFDtCnQ7iwnChxNNAF2wlvRA+6e9EYSYihhLhc8BHK3SJre2Q6XZ7CZEB3pYn8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=nNnqEWHG; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="nNnqEWHG" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=Fn+HB6bbM1pjLkNl/fg3PCRANt5VA3yO0I85pvryFgs=; b=nNnqEWHGHrf+MdshFlnRUY/mud 9cAXYnw5EQJe+lx4tYJe4gDW5vAUsAMDATd4hK7VfbU28ood6ydouUL4hYriiz2tY34cQdxUpMIJo nQ7OTUGTPc0cspu0OtxdT2MjqcekznW2sOc+xp7zdRoZQPdgqfLUv8JCHKGmKt+4L0emMov9XKdnY yU/nwayCNs4yZwFUlxNmQa+SdoXr0HKsJhPSCkGG0Eltk2rGC8wKDov0ANCbEwS3IFAs7BRsS92I+ wcwKZlmcgfR557yCH8C4K6JeDp6eXRribGyAzgwBGVmPXa3OfO3A1eyrwBSET78FhEn3WBcIAooKK anfq/0Cg==; Received: from [2001:4bb8:19a:62b2:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rd3Rd-00000003njL-0p4J; Thu, 22 Feb 2024 07:24:37 +0000 From: Christoph Hellwig To: Richard Weinberger , Anton Ivanov , Johannes Berg , Jens Axboe Cc: linux-um@lists.infradead.org, linux-block@vger.kernel.org Subject: [PATCH 7/7] ubd: open the backing files in ubd_add Date: Thu, 22 Feb 2024 08:24:17 +0100 Message-Id: <20240222072417.3773131-8-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240222072417.3773131-1-hch@lst.de> References: <20240222072417.3773131-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Opening the backing device only when the block device is opened is a bit weird as no one configures block devices to not use them. Opend them at add time, close them at remove time and remove the now superflous opened counter as remove can simply check for disk_openers. Signed-off-by: Christoph Hellwig Reviewed-by: Richard Weinberger --- arch/um/drivers/ubd_kern.c | 58 +++++++++++--------------------------- 1 file changed, 16 insertions(+), 42 deletions(-) diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c index 9bf1d6a88bae59..63fc062add708c 100644 --- a/arch/um/drivers/ubd_kern.c +++ b/arch/um/drivers/ubd_kern.c @@ -108,8 +108,6 @@ static inline void ubd_set_bit(__u64 bit, unsigned char *data) static DEFINE_MUTEX(ubd_lock); static DEFINE_MUTEX(ubd_mutex); /* replaces BKL, might not be needed */ -static int ubd_open(struct gendisk *disk, blk_mode_t mode); -static void ubd_release(struct gendisk *disk); static int ubd_ioctl(struct block_device *bdev, blk_mode_t mode, unsigned int cmd, unsigned long arg); static int ubd_getgeo(struct block_device *bdev, struct hd_geometry *geo); @@ -118,8 +116,6 @@ static int ubd_getgeo(struct block_device *bdev, struct hd_geometry *geo); static const struct block_device_operations ubd_blops = { .owner = THIS_MODULE, - .open = ubd_open, - .release = ubd_release, .ioctl = ubd_ioctl, .compat_ioctl = blkdev_compat_ptr_ioctl, .getgeo = ubd_getgeo, @@ -152,7 +148,6 @@ struct ubd { * backing or the cow file. */ char *file; char *serial; - int count; int fd; __u64 size; struct openflags boot_openflags; @@ -178,7 +173,6 @@ struct ubd { #define DEFAULT_UBD { \ .file = NULL, \ .serial = NULL, \ - .count = 0, \ .fd = -1, \ .size = -1, \ .boot_openflags = OPEN_FLAGS, \ @@ -873,6 +867,13 @@ static int ubd_add(int n, char **error_out) goto out; } + err = ubd_open_dev(ubd_dev); + if (err) { + pr_err("ubd%c: Can't open \"%s\": errno = %d\n", + 'a' + n, ubd_dev->file, -err); + goto out; + } + ubd_dev->size = ROUND_BLOCK(ubd_dev->size); ubd_dev->tag_set.ops = &ubd_mq_ops; @@ -884,7 +885,7 @@ static int ubd_add(int n, char **error_out) err = blk_mq_alloc_tag_set(&ubd_dev->tag_set); if (err) - goto out; + goto out_close; disk = blk_mq_alloc_disk(&ubd_dev->tag_set, &lim, ubd_dev); if (IS_ERR(disk)) { @@ -919,6 +920,8 @@ static int ubd_add(int n, char **error_out) put_disk(disk); out_cleanup_tags: blk_mq_free_tag_set(&ubd_dev->tag_set); +out_close: + ubd_close_dev(ubd_dev); out: return err; } @@ -1014,13 +1017,14 @@ static int ubd_remove(int n, char **error_out) if(ubd_dev->file == NULL) goto out; - /* you cannot remove a open disk */ - err = -EBUSY; - if(ubd_dev->count > 0) - goto out; - if (ubd_dev->disk) { + /* you cannot remove a open disk */ + err = -EBUSY; + if (disk_openers(ubd_dev->disk)) + goto out; + del_gendisk(ubd_dev->disk); + ubd_close_dev(ubd_dev); put_disk(ubd_dev->disk); } @@ -1143,36 +1147,6 @@ static int __init ubd_driver_init(void){ device_initcall(ubd_driver_init); -static int ubd_open(struct gendisk *disk, blk_mode_t mode) -{ - struct ubd *ubd_dev = disk->private_data; - int err = 0; - - mutex_lock(&ubd_mutex); - if(ubd_dev->count == 0){ - err = ubd_open_dev(ubd_dev); - if(err){ - printk(KERN_ERR "%s: Can't open \"%s\": errno = %d\n", - disk->disk_name, ubd_dev->file, -err); - goto out; - } - } - ubd_dev->count++; -out: - mutex_unlock(&ubd_mutex); - return err; -} - -static void ubd_release(struct gendisk *disk) -{ - struct ubd *ubd_dev = disk->private_data; - - mutex_lock(&ubd_mutex); - if(--ubd_dev->count == 0) - ubd_close_dev(ubd_dev); - mutex_unlock(&ubd_mutex); -} - static void cowify_bitmap(__u64 io_offset, int length, unsigned long *cow_mask, __u64 *cow_offset, unsigned long *bitmap, __u64 bitmap_offset, unsigned long *bitmap_words,