Skip to contentSkip to conversation

cifs: handle -EINTR in cifs_setattr

PATCH In review Ronnie Sahlberg 4 participants 5 messages Oct 6, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cifs: handle -EINTR in cifs_setattr

RHBZ: 1848178

Some calls that set attributes, like utimensat(), are not supposed to return -EINTR and thus do not have handlers for this in glibc which causes us to leak -EINTR to the applications which are also unprepared to handle it.

For example tar will break if utimensat() return -EINTR and abort unpacking the archive. Other applications may break too.

To handle this we add checks, and retry, for -EINTR in cifs_setattr()

---
 fs/cifs/inode.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
fs/cifs/inode.c +8 -4
index 3989d08396ac..74ed12f2c8aa 100644
@@ -2879,13 +2879,17 @@ cifs_setattr(struct dentry *direntry, struct iattr *attrs)
 {
 	struct cifs_sb_info *cifs_sb = CIFS_SB(direntry->d_sb);
 	struct cifs_tcon *pTcon = cifs_sb_master_tcon(cifs_sb);
+	int rc;
 
-	if (pTcon->unix_ext)
-		return cifs_setattr_unix(direntry, attrs);
-
-	return cifs_setattr_nounix(direntry, attrs);
+	do {
+		if (pTcon->unix_ext)
+			rc = cifs_setattr_unix(direntry, attrs);
+		else
+			rc = cifs_setattr_nounix(direntry, attrs);
+	} while (rc == -EINTR);
 
 	/* BB: add cifs_setattr_legacy for really old servers */
+	return rc;
 }
 
 #if 0
Signature · 1 line
2.13.6
#1 lore raw

tentatively merged into cifs-2.6.git for-next

Quoted 46 lines · Ronnie Sahlberg

RHBZ: 1848178

Some calls that set attributes, like utimensat(), are not supposed to return -EINTR and thus do not have handlers for this in glibc which causes us to leak -EINTR to the applications which are also unprepared to handle it.

For example tar will break if utimensat() return -EINTR and abort unpacking the archive. Other applications may break too.

To handle this we add checks, and retry, for -EINTR in cifs_setattr()

---
 fs/cifs/inode.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
fs/cifs/inode.c +8 -5
index 3989d08396ac..74ed12f2c8aa 100644
@@ -2879,13 +2879,17 @@ cifs_setattr(struct dentry *direntry, struct iattr *attrs)
 {
        struct cifs_sb_info *cifs_sb = CIFS_SB(direntry->d_sb);
        struct cifs_tcon *pTcon = cifs_sb_master_tcon(cifs_sb);
+       int rc;
 
-       if (pTcon->unix_ext)
-               return cifs_setattr_unix(direntry, attrs);
-
-       return cifs_setattr_nounix(direntry, attrs);
+       do {
+               if (pTcon->unix_ext)
+                       rc = cifs_setattr_unix(direntry, attrs);
+               else
+                       rc = cifs_setattr_nounix(direntry, attrs);
+       } while (rc == -EINTR);
 
        /* BB: add cifs_setattr_legacy for really old servers */
+       return rc;
 }
 
 #if 0
--

2.13.6

Signature · 3 lines
Thanks,

Steve
#2 lore raw

Question: What causes cifs_setattr_* to return -EINTR?
Does an infinite reattempt make sense here? Or should we give up after N attempts?
Also, should we cifsFYI log before we re-attempt?

Regards,
Shyam

Quoted 56 lines · Steve French

tentatively merged into cifs-2.6.git for-next

Quoted 44 lines · Ronnie Sahlberg

RHBZ: 1848178

Some calls that set attributes, like utimensat(), are not supposed to return -EINTR and thus do not have handlers for this in glibc which causes us to leak -EINTR to the applications which are also unprepared to handle it.

For example tar will break if utimensat() return -EINTR and abort unpacking the archive. Other applications may break too.

To handle this we add checks, and retry, for -EINTR in cifs_setattr()

---
 fs/cifs/inode.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
fs/cifs/inode.c +8 -5
index 3989d08396ac..74ed12f2c8aa 100644
@@ -2879,13 +2879,17 @@ cifs_setattr(struct dentry *direntry, struct iattr *attrs)
 {
        struct cifs_sb_info *cifs_sb = CIFS_SB(direntry->d_sb);
        struct cifs_tcon *pTcon = cifs_sb_master_tcon(cifs_sb);
+       int rc;
 
-       if (pTcon->unix_ext)
-               return cifs_setattr_unix(direntry, attrs);
-
-       return cifs_setattr_nounix(direntry, attrs);
+       do {
+               if (pTcon->unix_ext)
+                       rc = cifs_setattr_unix(direntry, attrs);
+               else
+                       rc = cifs_setattr_nounix(direntry, attrs);
+       } while (rc == -EINTR);
 
        /* BB: add cifs_setattr_legacy for really old servers */
+       return rc;
 }
 
 #if 0
--
Quoted 2 lines

2.13.6

--
Thanks,

Steve

Signature · 1 line
-Shyam
#3 lore raw

Ignore my second question. I got the answer in your description.

Quoted 71 lines · Shyam Prasad N

Question: What causes cifs_setattr_* to return -EINTR?
Does an infinite reattempt make sense here? Or should we give up after N attempts?
Also, should we cifsFYI log before we re-attempt?

Regards,
Shyam

Quoted 55 lines · Steve French

tentatively merged into cifs-2.6.git for-next

Quoted 44 lines · Ronnie Sahlberg

RHBZ: 1848178

Some calls that set attributes, like utimensat(), are not supposed to return -EINTR and thus do not have handlers for this in glibc which causes us to leak -EINTR to the applications which are also unprepared to handle it.

For example tar will break if utimensat() return -EINTR and abort unpacking the archive. Other applications may break too.

To handle this we add checks, and retry, for -EINTR in cifs_setattr()

---
 fs/cifs/inode.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
fs/cifs/inode.c +8 -5
index 3989d08396ac..74ed12f2c8aa 100644
@@ -2879,13 +2879,17 @@ cifs_setattr(struct dentry *direntry, struct iattr *attrs)
 {
        struct cifs_sb_info *cifs_sb = CIFS_SB(direntry->d_sb);
        struct cifs_tcon *pTcon = cifs_sb_master_tcon(cifs_sb);
+       int rc;
 
-       if (pTcon->unix_ext)
-               return cifs_setattr_unix(direntry, attrs);
-
-       return cifs_setattr_nounix(direntry, attrs);
+       do {
+               if (pTcon->unix_ext)
+                       rc = cifs_setattr_unix(direntry, attrs);
+               else
+                       rc = cifs_setattr_nounix(direntry, attrs);
+       } while (rc == -EINTR);
 
        /* BB: add cifs_setattr_legacy for really old servers */
+       return rc;
 }
 
 #if 0
--
Quoted 2 lines

2.13.6

--
Thanks,

Quoted 1 line

Steve

--
-Shyam

Signature · 1 line
-Shyam
#4 lore raw
In reply to Shyam Prasad N
Quoted 4 lines · Shyam Prasad N

Question: What causes cifs_setattr_* to return -EINTR?
Does an infinite reattempt make sense here? Or should we give up after N attempts?

Good question. Probably.
I think you are right we might need to limit the retries.

One case could be where we never receive a response from the server and userspace
wants to CTRL-C the thread. It might mean we have to do N CTRL-C to end the process but N is better than infinite CTRL-C :-)

I will resend with a limit on retries.

Thanks!

Quoted 67 lines

Also, should we cifsFYI log before we re-attempt?

Regards,
Shyam

Quoted 55 lines · Steve French

tentatively merged into cifs-2.6.git for-next

Quoted 44 lines · Ronnie Sahlberg

RHBZ: 1848178

Some calls that set attributes, like utimensat(), are not supposed to return -EINTR and thus do not have handlers for this in glibc which causes us to leak -EINTR to the applications which are also unprepared to handle it.

For example tar will break if utimensat() return -EINTR and abort unpacking the archive. Other applications may break too.

To handle this we add checks, and retry, for -EINTR in cifs_setattr()

---
 fs/cifs/inode.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
fs/cifs/inode.c +8 -5
index 3989d08396ac..74ed12f2c8aa 100644
@@ -2879,13 +2879,17 @@ cifs_setattr(struct dentry *direntry, struct iattr *attrs)
 {
        struct cifs_sb_info *cifs_sb = CIFS_SB(direntry->d_sb);
        struct cifs_tcon *pTcon = cifs_sb_master_tcon(cifs_sb);
+       int rc;
 
-       if (pTcon->unix_ext)
-               return cifs_setattr_unix(direntry, attrs);
-
-       return cifs_setattr_nounix(direntry, attrs);
+       do {
+               if (pTcon->unix_ext)
+                       rc = cifs_setattr_unix(direntry, attrs);
+               else
+                       rc = cifs_setattr_nounix(direntry, attrs);
+       } while (rc == -EINTR);
 
        /* BB: add cifs_setattr_legacy for really old servers */
+       return rc;
 }
 
 #if 0
--
Quoted 2 lines

2.13.6

--
Thanks,

Quoted 1 line

Steve

--
-Shyam