Skip to contentSkip to conversation

mount: avoid po_destroy to modify errno what we really want

PATCH In review Mi Jinlong 4 participants 6 messages Nov 25, 2010 – Dec 1, 2010

Subsystems (2)
lore
Share & tools
lore

Mi Jinlong

author
#0 lore raw

PATCH 1/1 mount: avoid po_destroy to modify errno what we really want

We should return the errno that was set before po_destroy, rather than the errno that was set at po_destroy.

Because the po_destroy function don't affect the return value, this patch just revert the saved errno after po_destroy.

---
 utils/mount/stropts.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
utils/mount/stropts.c +6 -2
index 50a1a2a..d554877 100644
@@ -592,7 +592,7 @@ static int nfs_do_mount_v3v2(struct nfsmount_info *mi,
 		struct sockaddr *sap, socklen_t salen)
 {
 	struct mount_options *options = po_dup(mi->options);
-	int result = 0;
+	int result = 0, save = 0;
 
 	if (!options) {
 		errno = ENOMEM;
@@ -637,7 +637,9 @@ static int nfs_do_mount_v3v2(struct nfsmount_info *mi,
 	result = nfs_sys_mount(mi, options);
 
 out_fail:
+	save = errno;
 	po_destroy(options);
+	errno = save;
 	return result;
 }
 
@@ -673,7 +675,7 @@ static int nfs_do_mount_v4(struct nfsmount_info *mi,
 		struct sockaddr *sap, socklen_t salen)
 {
 	struct mount_options *options = po_dup(mi->options);
-	int result = 0;
+	int result = 0, save = 0;
 
 	if (!options) {
 		errno = ENOMEM;
@@ -724,7 +726,9 @@ static int nfs_do_mount_v4(struct nfsmount_info *mi,
 	result = nfs_sys_mount(mi, options);
 
 out_fail:
+	save = errno;
 	po_destroy(options);
+	errno = save;
 	return result;
 }
 
Signature · 1 line
1.7.3.2
#1 lore raw
Quoted 5 lines · Mi Jinlong

We should return the errno that was set before po_destroy, rather than the errno that was set at po_destroy.

Because the po_destroy function don't affect the return value, this patch just revert the saved errno after po_destroy.

The only library function used in po_destroy() is free(3). Does free(3) change the value of errno?

Quoted 56 lines

---
utils/mount/stropts.c | 8 ++++++--

1 files changed, 6 insertions(+), 2 deletions(-)
utils/mount/stropts.c +1 -1
index 50a1a2a..d554877 100644
@@ -592,7 +592,7 @@ static int nfs_do_mount_v3v2(struct nfsmount_info *mi,
 		struct sockaddr *sap, socklen_t salen)
 {
 	struct mount_options *options = po_dup(mi->options);
-	int result = 0;
+	int result = 0, save = 0;
 
 	if (!options) {
 		errno = ENOMEM;
@@ -637,7 +637,9 @@ static int nfs_do_mount_v3v2(struct nfsmount_info *mi,
 	result = nfs_sys_mount(mi, options);
 

out_fail:

utils/mount/stropts.c +1 -0
+	save = errno;
	po_destroy(options);
utils/mount/stropts.c +1 -0
+	errno = save;
	return result;
}
utils/mount/stropts.c +1 -1
@@ -673,7 +675,7 @@ static int nfs_do_mount_v4(struct nfsmount_info *mi,
 		struct sockaddr *sap, socklen_t salen)
 {
 	struct mount_options *options = po_dup(mi->options);
-	int result = 0;
+	int result = 0, save = 0;
 
 	if (!options) {
 		errno = ENOMEM;
@@ -724,7 +726,9 @@ static int nfs_do_mount_v4(struct nfsmount_info *mi,
 	result = nfs_sys_mount(mi, options);
 

out_fail:

utils/mount/stropts.c +1 -0
+	save = errno;
	po_destroy(options);
utils/mount/stropts.c +1 -0
+	errno = save;
	return result;
}
Signature · 7 lines
1.7.3.2


--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
#2 lore raw
Quoted 11 lines · Chuck Lever
Quoted 5 lines · Mi Jinlong

We should return the errno that was set before po_destroy, rather than the errno that was set at po_destroy.

Because the po_destroy function don't affect the return value, this patch just revert the saved errno after po_destroy.

The only library function used in po_destroy() is free(3). Does free(3) change the value of errno?

Looking at the man page and taking a look a the
glibc code it appears the answer is no. free(3)
does not set errno.

Bian, what was the problem you were seeing that this patch fixed?

steved.

Quoted 58 lines
Quoted 57 lines

---
utils/mount/stropts.c | 8 ++++++--

1 files changed, 6 insertions(+), 2 deletions(-)
utils/mount/stropts.c +1 -1
index 50a1a2a..d554877 100644
@@ -592,7 +592,7 @@ static int nfs_do_mount_v3v2(struct nfsmount_info *mi,
 		struct sockaddr *sap, socklen_t salen)
 {
 	struct mount_options *options = po_dup(mi->options);
-	int result = 0;
+	int result = 0, save = 0;
 
 	if (!options) {
 		errno = ENOMEM;
@@ -637,7 +637,9 @@ static int nfs_do_mount_v3v2(struct nfsmount_info *mi,
 	result = nfs_sys_mount(mi, options);
 

out_fail:

utils/mount/stropts.c +1 -0
+	save = errno;
	po_destroy(options);
utils/mount/stropts.c +1 -0
+	errno = save;
	return result;
}
utils/mount/stropts.c +1 -1
@@ -673,7 +675,7 @@ static int nfs_do_mount_v4(struct nfsmount_info *mi,
 		struct sockaddr *sap, socklen_t salen)
 {
 	struct mount_options *options = po_dup(mi->options);
-	int result = 0;
+	int result = 0, save = 0;
 
 	if (!options) {
 		errno = ENOMEM;
@@ -724,7 +726,9 @@ static int nfs_do_mount_v4(struct nfsmount_info *mi,
 	result = nfs_sys_mount(mi, options);
 

out_fail:

utils/mount/stropts.c +1 -0
+	save = errno;
	po_destroy(options);
utils/mount/stropts.c +1 -0
+	errno = save;
	return result;
}
Signature · 7 lines
1.7.3.2


--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw
Quoted 9 lines · Steve Dickson
Quoted 7 lines · Chuck Lever
Quoted 5 lines · Mi Jinlong

We should return the errno that was set before po_destroy, rather than the errno that was set at po_destroy.

Because the po_destroy function don't affect the return value, this patch just revert the saved errno after po_destroy.

Quoted 9 lines
Quoted 2 lines

The only library function used in po_destroy() is free(3). Does free(3) change the value of errno?

Looking at the man page and taking a look a the
glibc code it appears the answer is no. free(3)
does not set errno.

Bian, what was the problem you were seeing that this patch fixed?

Actually, there's no problem now. But this's not a good style, po_destroy
maybe change the errno later on such as adding a printf.
So if somebady want modify the po_destroy, he must be careful of it. :)

And, i don't think it's a good idea that explicitly set errno, it maybe make some trouble in the future. It's better returning error in nfs_do_mount_v3v2, or save the error in a input parameter. :)

Thanks
Bian

Quoted 64 lines

steved.

Quoted 48 lines
Quoted 48 lines

---
utils/mount/stropts.c | 8 ++++++--

1 files changed, 6 insertions(+), 2 deletions(-)
utils/mount/stropts.c +1 -1
index 50a1a2a..d554877 100644
@@ -592,7 +592,7 @@ static int nfs_do_mount_v3v2(struct nfsmount_info *mi,
 		struct sockaddr *sap, socklen_t salen)
 {
 	struct mount_options *options = po_dup(mi->options);
-	int result = 0;
+	int result = 0, save = 0;
 
 	if (!options) {
 		errno = ENOMEM;
@@ -637,7 +637,9 @@ static int nfs_do_mount_v3v2(struct nfsmount_info *mi,
 	result = nfs_sys_mount(mi, options);
 

out_fail:

utils/mount/stropts.c +1 -0
+	save = errno;
	po_destroy(options);
utils/mount/stropts.c +1 -0
+	errno = save;
	return result;
}
utils/mount/stropts.c +1 -1
@@ -673,7 +675,7 @@ static int nfs_do_mount_v4(struct nfsmount_info *mi,
 		struct sockaddr *sap, socklen_t salen)
 {
 	struct mount_options *options = po_dup(mi->options);
-	int result = 0;
+	int result = 0, save = 0;
 
 	if (!options) {
 		errno = ENOMEM;
@@ -724,7 +726,9 @@ static int nfs_do_mount_v4(struct nfsmount_info *mi,
 	result = nfs_sys_mount(mi, options);
 

out_fail:

utils/mount/stropts.c +1 -0
+	save = errno;
	po_destroy(options);
utils/mount/stropts.c +1 -0
+	errno = save;
	return result;
}
Quoted 8 lines
Quoted 8 lines
Signature · 7 lines
1.7.3.2


--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Regards
Bian Naimeng
#4 lore raw

Hi Bian

Quoted 22 lines · Bian Naimeng
Quoted 9 lines · Steve Dickson
Quoted 7 lines · Chuck Lever
Quoted 5 lines · Mi Jinlong

We should return the errno that was set before po_destroy, rather than the errno that was set at po_destroy.

Because the po_destroy function don't affect the return value, this patch just revert the saved errno after po_destroy.

Quoted 9 lines
Quoted 2 lines

The only library function used in po_destroy() is free(3). Does free(3) change the value of errno?

Looking at the man page and taking a look a the
glibc code it appears the answer is no. free(3)
does not set errno.

Bian, what was the problem you were seeing that this patch fixed?

Quoted 7 lines

Actually, there's no problem now. But this's not a good style, po_destroy maybe change the errno later on such as adding a printf.
So if somebady want modify the po_destroy, he must be careful of it. :)

And, i don't think it's a good idea that explicitly set errno, it maybe make some trouble in the future. It's better returning error in nfs_do_mount_v3v2, or save the error in a input parameter. :)

Perhaps it isn't good style, but I'd rather see all of stropts.c updated to pass errno as an explicit parameter than to have it changed piecemeal. I agree that we run into trouble everywhere in mount with errno.

I think this particular patch is unnecessary until we have a need for it. Basically it confuses a reviewer who sees that we've gone to the trouble here to save and restore errno, but nowhere else, and besides po_destroy() doesn't even alter errno. Why are we bothering?

Quoted 72 lines

Thanks
Bian

Quoted 64 lines

steved.

Quoted 48 lines
Quoted 48 lines

---
utils/mount/stropts.c | 8 ++++++--

1 files changed, 6 insertions(+), 2 deletions(-)
utils/mount/stropts.c +1 -1
index 50a1a2a..d554877 100644
@@ -592,7 +592,7 @@ static int nfs_do_mount_v3v2(struct nfsmount_info *mi,
 		struct sockaddr *sap, socklen_t salen)
 {
 	struct mount_options *options = po_dup(mi->options);
-	int result = 0;
+	int result = 0, save = 0;
 
 	if (!options) {
 		errno = ENOMEM;
@@ -637,7 +637,9 @@ static int nfs_do_mount_v3v2(struct nfsmount_info *mi,
 	result = nfs_sys_mount(mi, options);
 

out_fail:

utils/mount/stropts.c +1 -0
+	save = errno;
	po_destroy(options);
utils/mount/stropts.c +1 -0
+	errno = save;
	return result;
}
utils/mount/stropts.c +1 -1
@@ -673,7 +675,7 @@ static int nfs_do_mount_v4(struct nfsmount_info *mi,
 		struct sockaddr *sap, socklen_t salen)
 {
 	struct mount_options *options = po_dup(mi->options);
-	int result = 0;
+	int result = 0, save = 0;
 
 	if (!options) {
 		errno = ENOMEM;
@@ -724,7 +726,9 @@ static int nfs_do_mount_v4(struct nfsmount_info *mi,
 	result = nfs_sys_mount(mi, options);
 

out_fail:

utils/mount/stropts.c +1 -0
+	save = errno;
	po_destroy(options);
utils/mount/stropts.c +1 -0
+	errno = save;
	return result;
}
Quoted 8 lines
Quoted 8 lines
Signature · 7 lines
1.7.3.2


--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Regards
Bian Naimeng
Signature · 2 lines
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
#5 lore raw
Quoted 27 lines · Chuck Lever

Hi Bian

Quoted 23 lines · Bian Naimeng
Quoted 8 lines · Steve Dickson
Quoted 7 lines · Chuck Lever
Quoted 5 lines · Mi Jinlong

We should return the errno that was set before po_destroy, rather than the errno that was set at po_destroy.

Because the po_destroy function don't affect the return value, this patch just revert the saved errno after po_destroy.

Quoted 9 lines
Quoted 2 lines

The only library function used in po_destroy() is free(3). Does free(3) change the value of errno?

Looking at the man page and taking a look a the
glibc code it appears the answer is no. free(3)
does not set errno.

Bian, what was the problem you were seeing that this patch fixed?

Actually, there's no problem now. But this's not a good style, po_destroy maybe change the errno later on such as adding a printf.
So if somebady want modify the po_destroy, he must be careful of it. :)

Quoted 8 lines
Quoted 3 lines

And, i don't think it's a good idea that explicitly set errno, it maybe make some trouble in the future. It's better returning error in nfs_do_mount_v3v2, or save the error in a input parameter. :)

Perhaps it isn't good style, but I'd rather see all of stropts.c updated to pass errno as an explicit parameter than to have it changed piecemeal. I agree that we run into trouble everywhere in mount with errno.

I think this particular patch is unnecessary until we have a need for it. Basically it confuses a reviewer who sees that we've gone to the trouble here to save and restore errno, but nowhere else, and besides po_destroy() doesn't even alter errno. Why are we bothering?

Well, it's okay to me.

Thanks
Bian

Quoted 69 lines
Quoted 68 lines
Quoted 64 lines

steved.

Quoted 48 lines
Quoted 48 lines

---
utils/mount/stropts.c | 8 ++++++--

1 files changed, 6 insertions(+), 2 deletions(-)
utils/mount/stropts.c +1 -1
index 50a1a2a..d554877 100644
@@ -592,7 +592,7 @@ static int nfs_do_mount_v3v2(struct nfsmount_info *mi,
 		struct sockaddr *sap, socklen_t salen)
 {
 	struct mount_options *options = po_dup(mi->options);
-	int result = 0;
+	int result = 0, save = 0;
 
 	if (!options) {
 		errno = ENOMEM;
@@ -637,7 +637,9 @@ static int nfs_do_mount_v3v2(struct nfsmount_info *mi,
 	result = nfs_sys_mount(mi, options);
 

out_fail:

utils/mount/stropts.c +1 -0
+	save = errno;
	po_destroy(options);
utils/mount/stropts.c +1 -0
+	errno = save;
	return result;
}
utils/mount/stropts.c +1 -1
@@ -673,7 +675,7 @@ static int nfs_do_mount_v4(struct nfsmount_info *mi,
 		struct sockaddr *sap, socklen_t salen)
 {
 	struct mount_options *options = po_dup(mi->options);
-	int result = 0;
+	int result = 0, save = 0;
 
 	if (!options) {
 		errno = ENOMEM;
@@ -724,7 +726,9 @@ static int nfs_do_mount_v4(struct nfsmount_info *mi,
 	result = nfs_sys_mount(mi, options);
 

out_fail:

utils/mount/stropts.c +1 -0
+	save = errno;
	po_destroy(options);
utils/mount/stropts.c +1 -0
+	errno = save;
	return result;
}
Quoted 8 lines
Quoted 8 lines
Signature · 7 lines
1.7.3.2


--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Regards
Bian Naimeng
Signature · 2 lines
Regards
Bian Naimeng