linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Andrey Jr. Melnikov" <temnota.am@gmail.com>
To: linux-raid@vger.kernel.org
Subject: Re: [PATCH V2 1/2] Check hostname file empty or not when creating raid device
Date: Tue, 15 Sep 2020 18:27:29 +0300	[thread overview]
Message-ID: <v3373h-8sh.ln1@banana.localnet> (raw)
In-Reply-To: 1600155882-4488-2-git-send-email-xni@redhat.com

Xiao Ni <xni@redhat.com> wrote:
> If /etc/hostname is empty and the hostname is decided by network(dhcp, e.g.), there is a
> risk that raid device will not be in active state after boot. It will be auto-read-only
> state. It depends on the boot sequence. If the storage starts before network. The system
> detects disks first, udev rules are triggered and raid device is assemble automatically.
> But the network hasn't started successfully. So mdadm can't get the right hostname. The
> raid device will be treated as a foreign raid.
> Add a note message if /etc/hostname is empty when creating a raid device.

> Signed-off-by: Xiao Ni <xni@redhat.com>
> ---
>  mdadm.c |  3 +++
>  mdadm.h |  1 +
>  util.c  | 19 +++++++++++++++++++
>  3 files changed, 23 insertions(+)

> diff --git a/mdadm.c b/mdadm.c
> index 1b3467f..e551958 100644
> --- a/mdadm.c
> +++ b/mdadm.c
> @@ -1408,6 +1408,9 @@ int main(int argc, char *argv[])
>         if (c.homehost == NULL && c.require_homehost)
>                 c.homehost = conf_get_homehost(&c.require_homehost);
>         if (c.homehost == NULL || strcasecmp(c.homehost, "<system>") == 0) {
> +               if (check_hostname())
> +                       pr_err("Note: The file /etc/hostname is empty. There is a risk the raid\n"
> +                               "      can't be active after boot\n");
>                 if (gethostname(sys_hostname, sizeof(sys_hostname)) == 0) {
>                         sys_hostname[sizeof(sys_hostname)-1] = 0;
>                         c.homehost = sys_hostname;
> diff --git a/mdadm.h b/mdadm.h
> index 399478b..3ef1209 100644
> --- a/mdadm.h
> +++ b/mdadm.h
> @@ -1480,6 +1480,7 @@ extern int parse_cluster_confirm_arg(char *inp, char **devname, int *slot);
>  extern int check_ext2(int fd, char *name);
>  extern int check_reiser(int fd, char *name);
>  extern int check_raid(int fd, char *name);
> +extern int check_hostname(void);
>  extern int check_partitions(int fd, char *dname,
>                             unsigned long long freesize,
>                             unsigned long long size);
> diff --git a/util.c b/util.c
> index 579dd42..de5bad0 100644
> --- a/util.c
> +++ b/util.c
> @@ -694,6 +694,25 @@ int check_raid(int fd, char *name)
>         return 1;
>  }
>  
> +/* It checks /etc/hostname has value or not */
> +int check_hostname()
> +{
> +       int fd, ret = 0;
> +       char buf[256];
> +
> +       fd = open("/etc/hostname", O_RDONLY);
> +       if (fd < 0) {
> +               ret = 1;
> +               goto out;
> +       }
> +
> +       if (read(fd, buf, sizeof(buf)) == 0)
> +               ret = 1;

Why not use stat() here, since you don't use file content?
Also, any error from read() - mean file "not empty". This is right?

> +out:
> +       close(fd);
> +       return ret;
> +}
> +
>  int fstat_is_blkdev(int fd, char *devname, dev_t *rdev)
>  {
>         struct stat stb;


  reply	other threads:[~2020-09-15 15:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-15  7:44 [PATCH V2 0/2] Some fixes for mdadm Xiao Ni
2020-09-15  7:44 ` [PATCH V2 1/2] Check hostname file empty or not when creating raid device Xiao Ni
2020-09-15 15:27   ` Andrey Jr. Melnikov [this message]
2020-10-14 15:22   ` Jes Sorensen
2020-10-15 13:40     ` Xiao Ni
2020-09-15  7:44 ` [PATCH V2 2/2] Don't create bitmap for raid5 with journal disk Xiao Ni
2020-10-14 15:25   ` Jes Sorensen

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=v3373h-8sh.ln1@banana.localnet \
    --to=temnota.am@gmail.com \
    --cc=linux-raid@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).