All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Pargmann <mpa@pengutronix.de>
To: Paul Clements <Paul.Clements@steeleye.com>
Cc: nbd-general@lists.sourceforge.net, linux-kernel@vger.kernel.org,
	kernel@pengutronix.de
Subject: Re: [RFC 4/4] nbd: Add support for nbd as root device
Date: Tue, 20 Jan 2015 12:51:05 +0100	[thread overview]
Message-ID: <20150120115105.GA26529@pengutronix.de> (raw)
In-Reply-To: <1421156665-27318-5-git-send-email-mpa@pengutronix.de>

[-- Attachment #1: Type: text/plain, Size: 3513 bytes --]

On Tue, Jan 13, 2015 at 02:44:25PM +0100, Markus Pargmann wrote:
> Adding support to nbd to use it as a root device. This code essentially
> provides a minimal nbd-client implementation within the kernel. It opens
> a socket and makes the negotiation with the server. Afterwards it passes
> the socket to the normal nbd-code to handle the connection.
> 
> The arguments for the server are passed via module parameter. The
> module parameter has the format
> '[<SERVER_IP>:]<SERVER_PORT>/<EXPORT_NAME>'.
> SERVER_IP is optional. If it is not available it will use the
> root_server_addr transmitted through DHCP.
> 
> Based on those arguments, the connection to the server is established
> and is connected to the nbd0 device. The rootdevice therefore is
> root=/dev/nbd0.
> 
> Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
> ---
>  drivers/block/nbd.c | 306 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 306 insertions(+)
> 
> diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
> index 11f7644be111..ac881ae3c15a 100644
> --- a/drivers/block/nbd.c
> +++ b/drivers/block/nbd.c
> @@ -32,12 +32,17 @@
>  #include <net/sock.h>
>  #include <linux/net.h>
>  #include <linux/kthread.h>
> +#include <net/ipconfig.h>
> +#include <linux/in.h>
> +#include <linux/tcp.h>
>  
>  #include <asm/uaccess.h>
>  #include <asm/types.h>
>  
>  #include <linux/nbd.h>
>  
> +#define ADDR_NONE cpu_to_be32(INADDR_NONE)
> +
>  #define NBD_MAGIC 0x68797548
>  
>  #ifdef NDEBUG
> @@ -71,6 +76,20 @@ static int max_part;
>   */
>  static DEFINE_SPINLOCK(nbd_lock);
>  
> +static const char nbd_magic[] = "NBDMAGIC";
> +static const u64 nbd_opts_magic = 0x49484156454F5054LL;
> +
> +/* Options used for the kernel driver */
> +#define NBD_OPT_EXPORT_NAME 1
> +
> +#define NBD_DEFAULT_BLOCKSIZE 1024
> +
> +extern __be32 root_nfs_parse_addr(char *name);
> +
> +static __be32 nbd_server_addr = ADDR_NONE;
> +static __be32 nbd_server_port;
> +static char nbd_server_export[128] = "";
> +
>  #ifndef NDEBUG
>  static const char *ioctl_cmd_to_ascii(int cmd)
>  {
> @@ -105,6 +124,52 @@ static const char *nbdcmd_to_ascii(int cmd)
>  }
>  #endif /* NDEBUG */
>  
> +/*
> + * Parse format "[<SERVER_IP>:]<SERVER_PORT>/<EXPORT_NAME>"
> + */
> +static int nbd_server_addr_set(const char *val, const struct kernel_param *kp)
> +{
> +	char *export;
> +	u16 port;
> +	int ret;
> +	char buf[128];
> +
> +	strncpy(buf, val, 128);
> +
> +	nbd_server_addr = root_nfs_parse_addr(buf);
> +
> +	if (*buf == '\0') {
> +		ret = -EINVAL;
> +		goto free_buf;
> +	}
> +	export = strchr(buf, '/');
> +	if (!export || *(export + 1) == '\0') {
> +		ret = -EINVAL;
> +		goto free_buf;
> +	}
> +	*export = '\0';
> +	++export;
> +
> +	ret = kstrtou16(buf, 10, &port);
> +	if (ret)
> +		goto free_buf;
> +
> +	memmove(buf, export, strlen(export) + 1);

This memmove() is a leftover from a previous version, it is removed for
the next series version. I also added some documentation patches that
describe this feature in Documentation/blockdev/nbd.txt. I will send it
at the end of this week.

Best regards,

Markus

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  reply	other threads:[~2015-01-20 11:51 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-13 13:44 [RFC 0/4] nbd: root device support Markus Pargmann
2015-01-13 13:44 ` [RFC 1/4] nbd: Replace kthread_create with kthread_run Markus Pargmann
2015-01-13 13:44 ` [RFC 2/4] nbd: Split 'DO_IT' into three functions Markus Pargmann
2015-01-26 16:16   ` Paul Clements
2015-01-26 16:23     ` Markus Pargmann
2015-01-13 13:44 ` [RFC 3/4] nbd: Create helper functions for ioctls Markus Pargmann
2015-01-28 21:04   ` Paul Clements
2015-01-30  7:54     ` Markus Pargmann
2015-01-13 13:44 ` [RFC 4/4] nbd: Add support for nbd as root device Markus Pargmann
2015-01-20 11:51   ` Markus Pargmann [this message]
2015-01-29 23:42   ` [Nbd] " Wouter Verhelst
2015-01-30  8:04     ` Markus Pargmann
2015-01-30 17:30       ` Wouter Verhelst
2015-01-31 12:38         ` Markus Pargmann
     [not found]           ` <CAECXXi5+VhBeZwZ5aosc+Oc+0bCZbJZTjzYA-QTRrJCjs2NFOw@mail.gmail.com>
2015-01-31 14:43             ` Andreas Klauer
2015-01-31 15:45               ` Markus Pargmann
2015-01-31 15:00             ` Markus Pargmann
2015-01-30 18:10       ` [Nbd] " H. Peter Anvin
2015-01-31 12:08         ` Markus Pargmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150120115105.GA26529@pengutronix.de \
    --to=mpa@pengutronix.de \
    --cc=Paul.Clements@steeleye.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nbd-general@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.