[Devel,1/2] mounts: add unsupported mount helper

Submitted by Stanislav Kinsburskiy on June 20, 2017, 3:28 p.m.

Details

Message ID 20170620152858.31119.27652.stgit@skinsbursky-vz7.qa.sw.ru
State New
Series "mounts: fix check for overmounted NFS"
Headers show

Commit Message

Stanislav Kinsburskiy June 20, 2017, 3:28 p.m.
Call it on mount points tree building and abort in case NFS is overmounted.
This logic replaces the old one, which was checking for unsupported NFS monut
in validate_mounts. And the reason is that call to validate_mounts depends on
user argument, which is unsuitable for this case.

Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
---
 criu/mount.c |   35 ++++++++++++++++++++++-------------
 1 file changed, 22 insertions(+), 13 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/mount.c b/criu/mount.c
index cc54e68..46ad66c 100644
--- a/criu/mount.c
+++ b/criu/mount.c
@@ -397,6 +397,25 @@  static bool mounts_equal(struct mount_info *a, struct mount_info *b)
  */
 static char *mnt_roots;
 
+static bool nfs_mount(const struct mount_info *m)
+{
+	return !strcmp(m->fstype->name, "nfs") ||
+	       !strcmp(m->fstype->name, "nfs4");
+
+}
+
+static bool unsupported_mount(const struct mount_info *m)
+{
+	struct mount_info *parent = m->parent;
+
+	if (m->parent && nfs_mount(parent)) {
+		pr_err("overmounted NFS (%s) is not supported yet:\n",
+				parent->mountpoint);
+		return true;
+	}
+	return false;
+}
+
 static struct mount_info *mnt_build_ids_tree(struct mount_info *list, struct mount_info *yard_mount)
 {
 	struct mount_info *m, *root = NULL;
@@ -457,6 +476,9 @@  static struct mount_info *mnt_build_ids_tree(struct mount_info *list, struct mou
 
 		m->parent = parent;
 		list_add_tail(&m->siblings, &parent->children);
+
+		if (unsupported_mount(m))
+			return NULL;
 	}
 
 	if (!root) {
@@ -739,16 +761,6 @@  static bool mnt_is_external(struct mount_info *m)
 	return 0;
 }
 
-static bool unsupported_nfs_mount(struct mount_info *m)
-{
-	if (!list_empty(&m->children)) {
-		pr_err("overmounted NFS (%s) is not supported yet\n",
-				m->mountpoint);
-		return true;
-	}
-	return false;
-}
-
 static int validate_mounts(struct mount_info *info, bool for_dump)
 {
 	struct mount_info *m, *t;
@@ -819,9 +831,6 @@  skip_fstype:
 					m->mnt_id, m->mountpoint);
 			return -1;
 		}
-
-		if (!strcmp(m->fstype->name, "nfs") && unsupported_nfs_mount(m))
-			return -1;
 	}
 
 	return 0;

Comments

Kirill Tkhai June 20, 2017, 3:46 p.m.
One minor nit below

On Tue, Jun 20, 2017 at 18:28, Stanislav Kinsburskiy wrote:
> Call it on mount points tree building and abort in case NFS is overmounted.
> This logic replaces the old one, which was checking for unsupported NFS monut
> in validate_mounts. And the reason is that call to validate_mounts depends on
> user argument, which is unsuitable for this case.
> 
> Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
> ---
>  criu/mount.c |   35 ++++++++++++++++++++++-------------
>  1 file changed, 22 insertions(+), 13 deletions(-)
> 
> diff --git a/criu/mount.c b/criu/mount.c
> index cc54e68..46ad66c 100644
> --- a/criu/mount.c
> +++ b/criu/mount.c
> @@ -397,6 +397,25 @@ static bool mounts_equal(struct mount_info *a, struct mount_info *b)
>   */
>  static char *mnt_roots;
>  
> +static bool nfs_mount(const struct mount_info *m)
> +{
> +	return !strcmp(m->fstype->name, "nfs") ||
> +	       !strcmp(m->fstype->name, "nfs4");
> +
> +}
> +
> +static bool unsupported_mount(const struct mount_info *m)
> +{
> +	struct mount_info *parent = m->parent;
> +
> +	if (m->parent && nfs_mount(parent)) {

m->parent is already dereferenced, so you may use just "parent"
instead of it.

> +		pr_err("overmounted NFS (%s) is not supported yet:\n",
> +				parent->mountpoint);
> +		return true;
> +	}
> +	return false;
> +}
> +
>  static struct mount_info *mnt_build_ids_tree(struct mount_info *list, struct mount_info *yard_mount)
>  {
>  	struct mount_info *m, *root = NULL;
> @@ -457,6 +476,9 @@ static struct mount_info *mnt_build_ids_tree(struct mount_info *list, struct mou
>  
>  		m->parent = parent;
>  		list_add_tail(&m->siblings, &parent->children);
> +
> +		if (unsupported_mount(m))
> +			return NULL;
>  	}
>  
>  	if (!root) {
> @@ -739,16 +761,6 @@ static bool mnt_is_external(struct mount_info *m)
>  	return 0;
>  }
>  
> -static bool unsupported_nfs_mount(struct mount_info *m)
> -{
> -	if (!list_empty(&m->children)) {
> -		pr_err("overmounted NFS (%s) is not supported yet\n",
> -				m->mountpoint);
> -		return true;
> -	}
> -	return false;
> -}
> -
>  static int validate_mounts(struct mount_info *info, bool for_dump)
>  {
>  	struct mount_info *m, *t;
> @@ -819,9 +831,6 @@ skip_fstype:
>  					m->mnt_id, m->mountpoint);
>  			return -1;
>  		}
> -
> -		if (!strcmp(m->fstype->name, "nfs") && unsupported_nfs_mount(m))
> -			return -1;
>  	}
>  
>  	return 0;
> 
> _______________________________________________
> Devel mailing list
> Devel@openvz.org
> https://lists.openvz.org/mailman/listinfo/devel
Stanislav Kinsburskiy June 20, 2017, 3:54 p.m.
Thanks, Kirill!

I'm sorry, but this series is wrong.

I'll send another one soon.


20.06.2017 17:46, Kirill Tkhai пишет:
> One minor nit below
>
> On Tue, Jun 20, 2017 at 18:28, Stanislav Kinsburskiy wrote:
>> Call it on mount points tree building and abort in case NFS is overmounted.
>> This logic replaces the old one, which was checking for unsupported NFS monut
>> in validate_mounts. And the reason is that call to validate_mounts depends on
>> user argument, which is unsuitable for this case.
>>
>> Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
>> ---
>>   criu/mount.c |   35 ++++++++++++++++++++++-------------
>>   1 file changed, 22 insertions(+), 13 deletions(-)
>>
>> diff --git a/criu/mount.c b/criu/mount.c
>> index cc54e68..46ad66c 100644
>> --- a/criu/mount.c
>> +++ b/criu/mount.c
>> @@ -397,6 +397,25 @@ static bool mounts_equal(struct mount_info *a, struct mount_info *b)
>>    */
>>   static char *mnt_roots;
>>   
>> +static bool nfs_mount(const struct mount_info *m)
>> +{
>> +	return !strcmp(m->fstype->name, "nfs") ||
>> +	       !strcmp(m->fstype->name, "nfs4");
>> +
>> +}
>> +
>> +static bool unsupported_mount(const struct mount_info *m)
>> +{
>> +	struct mount_info *parent = m->parent;
>> +
>> +	if (m->parent && nfs_mount(parent)) {
> m->parent is already dereferenced, so you may use just "parent"
> instead of it.
>
>> +		pr_err("overmounted NFS (%s) is not supported yet:\n",
>> +				parent->mountpoint);
>> +		return true;
>> +	}
>> +	return false;
>> +}
>> +
>>   static struct mount_info *mnt_build_ids_tree(struct mount_info *list, struct mount_info *yard_mount)
>>   {
>>   	struct mount_info *m, *root = NULL;
>> @@ -457,6 +476,9 @@ static struct mount_info *mnt_build_ids_tree(struct mount_info *list, struct mou
>>   
>>   		m->parent = parent;
>>   		list_add_tail(&m->siblings, &parent->children);
>> +
>> +		if (unsupported_mount(m))
>> +			return NULL;
>>   	}
>>   
>>   	if (!root) {
>> @@ -739,16 +761,6 @@ static bool mnt_is_external(struct mount_info *m)
>>   	return 0;
>>   }
>>   
>> -static bool unsupported_nfs_mount(struct mount_info *m)
>> -{
>> -	if (!list_empty(&m->children)) {
>> -		pr_err("overmounted NFS (%s) is not supported yet\n",
>> -				m->mountpoint);
>> -		return true;
>> -	}
>> -	return false;
>> -}
>> -
>>   static int validate_mounts(struct mount_info *info, bool for_dump)
>>   {
>>   	struct mount_info *m, *t;
>> @@ -819,9 +831,6 @@ skip_fstype:
>>   					m->mnt_id, m->mountpoint);
>>   			return -1;
>>   		}
>> -
>> -		if (!strcmp(m->fstype->name, "nfs") && unsupported_nfs_mount(m))
>> -			return -1;
>>   	}
>>   
>>   	return 0;
>>
>> _______________________________________________
>> Devel mailing list
>> Devel@openvz.org
>> https://lists.openvz.org/mailman/listinfo/devel