Skip to contentSkip to conversation

cifs - cifs_find_tcp_session cleanup

PATCH In review Cyrill Gorcunov 2 participants 7 messages May 1, 2008 – May 9, 2008 1 message not in the archive

lore
Share & tools
lore
#3 lore raw

PATCH 2/2 cifs - cifs_find_tcp_session cleanup

In reply to a message not in the archive

This patch is to remove too indented code in cifs_find_tcp_session. Also memcmp was used wrongly - we would have found the session which IP6 addresses didn't match.

---

fs/cifs/connect.c +29 -27
Index: linux-2.6.git/fs/cifs/connect.c
===================================================================
@@ -1318,42 +1318,44 @@ cifs_parse_mount_options(char *options, 
 
 static struct cifsSesInfo *
 cifs_find_tcp_session(struct in_addr *target_ip_addr,
-		struct in6_addr *target_ip6_addr,
-		 char *userName, struct TCP_Server_Info **psrvTcp)
+		      struct in6_addr *target_ip6_addr,
+		      char *userName, struct TCP_Server_Info **psrvTcp)
 {
 	struct list_head *tmp;
 	struct cifsSesInfo *ses;
+
 	*psrvTcp = NULL;
-	read_lock(&GlobalSMBSeslock);
 
+	if (!target_ip_addr)
+		return NULL;
+
+	read_lock(&GlobalSMBSeslock);
 	list_for_each(tmp, &GlobalSMBSessionList) {
 		ses = list_entry(tmp, struct cifsSesInfo, cifsSessionList);
-		if (ses->server) {
-			if ((target_ip_addr &&
-				(ses->server->addr.sockAddr.sin_addr.s_addr
-				  == target_ip_addr->s_addr)) || (target_ip6_addr
-				&& memcmp(&ses->server->addr.sockAddr6.sin6_addr,
-					target_ip6_addr, sizeof(*target_ip6_addr)))) {
-				/* BB lock server and tcp session and increment
-				      use count here?? */
-
-				/* found a match on the TCP session */
-				*psrvTcp = ses->server;
-
-				/* BB check if reconnection needed */
-				if (strncmp
-				    (ses->userName, userName,
-				     MAX_USERNAME_SIZE) == 0){
-					read_unlock(&GlobalSMBSeslock);
-					/* Found exact match on both TCP and
-					   SMB sessions */
-					return ses;
-				}
-			}
-		}
-		/* else tcp and smb sessions need reconnection */
+		if (!ses->server)
+			continue;
+
+		if (ses->server->addr.sockAddr.sin_addr.s_addr != target_ip_addr->s_addr ||
+		    memcmp(&ses->server->addr.sockAddr6.sin6_addr,
+			   target_ip6_addr, sizeof(*target_ip6_addr)))
+			continue;
+
+		/* BB lock server and tcp session and increment
+		   use count here?? */
+
+		/* found a match on the TCP session */
+		*psrvTcp = ses->server;
+
+		/* BB check if reconnection needed */
+		if (strncmp(ses->userName, userName, MAX_USERNAME_SIZE))
+			continue;
+
+		/* Found exact match on both TCP and SMB sessions */
+		read_unlock(&GlobalSMBSeslock);
+		return ses;
 	}
 	read_unlock(&GlobalSMBSeslock);
+
 	return NULL;
 }
 
#1 lore raw

PATCH 1/2 cifs - find_unc cleanup

In reply to a message not in the archive

This patch is to remove too indented code in find_unc

---

fs/cifs/connect.c +31 -33
Index: linux-2.6.git/fs/cifs/connect.c
===================================================================
@@ -1362,45 +1362,43 @@ find_unc(__be32 new_target_ip_addr, char
 {
 	struct list_head *tmp;
 	struct cifsTconInfo *tcon;
+	__be32 old_ip;
 
 	read_lock(&GlobalSMBSeslock);
+
 	list_for_each(tmp, &GlobalTreeConnectionList) {
 		cFYI(1, ("Next tcon"));
 		tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
-		if (tcon->ses) {
-			if (tcon->ses->server) {
-				cFYI(1,
-				     ("old ip addr: %x == new ip %x ?",
-				      tcon->ses->server->addr.sockAddr.sin_addr.
-				      s_addr, new_target_ip_addr));
-				if (tcon->ses->server->addr.sockAddr.sin_addr.
-				    s_addr == new_target_ip_addr) {
-	/* BB lock tcon, server and tcp session and increment use count here? */
-					/* found a match on the TCP session */
-					/* BB check if reconnection needed */
-					cFYI(1,
-					      ("IP match, old UNC: %s new: %s",
-					      tcon->treeName, uncName));
-					if (strncmp
-					    (tcon->treeName, uncName,
-					     MAX_TREE_SIZE) == 0) {
-						cFYI(1,
-						     ("and old usr: %s new: %s",
-						      tcon->treeName, uncName));
-						if (strncmp
-						    (tcon->ses->userName,
-						     userName,
-						     MAX_USERNAME_SIZE) == 0) {
-							read_unlock(&GlobalSMBSeslock);
-							/* matched smb session
-							(user name */
-							return tcon;
-						}
-					}
-				}
-			}
-		}
+		if (!tcon->ses || !tcon->ses->server)
+			continue;
+
+		old_ip = tcon->ses->server->addr.sockAddr.sin_addr.s_addr;
+		cFYI(1, ("old ip addr: %x == new ip %x ?",
+			old_ip, new_target_ip_addr));
+
+		if (old_ip != new_target_ip_addr)
+			continue;
+
+		/* BB lock tcon, server and tcp session and increment use count here? */
+		/* found a match on the TCP session */
+		/* BB check if reconnection needed */
+		cFYI(1, ("IP match, old UNC: %s new: %s",
+			tcon->treeName, uncName));
+
+		if (strncmp(tcon->treeName, uncName, MAX_TREE_SIZE))
+			continue;
+
+		cFYI(1, ("and old usr: %s new: %s",
+			tcon->treeName, uncName));
+
+		if (strncmp(tcon->ses->userName, userName, MAX_USERNAME_SIZE))
+			continue;
+
+		/* matched smb session (user name) */
+		read_unlock(&GlobalSMBSeslock);
+		return tcon;
 	}
+
 	read_unlock(&GlobalSMBSeslock);
 	return NULL;
 }
#2 lore raw

Re: [patch 1/2] cifs - find_unc cleanup

merged

Quoted 89 lines · Cyrill Gorcunov

This patch is to remove too indented code in find_unc

---

Index: linux-2.6.git/fs/cifs/connect.c
===================================================================
--- linux-2.6.git.orig/fs/cifs/connect.c 2008-05-01 18:21:38.000000000 +0400
+++ linux-2.6.git/fs/cifs/connect.c 2008-05-01 19:02:51.000000000 +0400
@@ -1362,45 +1362,43 @@ find_unc(__be32 new_target_ip_addr, char

  {
        struct list_head *tmp;
        struct cifsTconInfo *tcon;

+ __be32 old_ip;

        read_lock(&GlobalSMBSeslock);
 +
        list_for_each(tmp, &GlobalTreeConnectionList) {
                cFYI(1, ("Next tcon"));
                tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
 -               if (tcon->ses) {
 -                       if (tcon->ses->server) {
 -                               cFYI(1,
 -                                    ("old ip addr: %x == new ip %x ?",
 -                                     tcon->ses->server->addr.sockAddr.sin_addr.
 -                                     s_addr, new_target_ip_addr));
 -                               if (tcon->ses->server->addr.sockAddr.sin_addr.
 -                                   s_addr == new_target_ip_addr) {
 -       /* BB lock tcon, server and tcp session and increment use count here? */
 -                                       /* found a match on the TCP session */
 -                                       /* BB check if reconnection needed */
 -                                       cFYI(1,
 -                                             ("IP match, old UNC: %s new: %s",
 -                                             tcon->treeName, uncName));
 -                                       if (strncmp
 -                                           (tcon->treeName, uncName,
 -                                            MAX_TREE_SIZE) == 0) {
 -                                               cFYI(1,
 -                                                    ("and old usr: %s new: %s",
 -                                                     tcon->treeName, uncName));
 -                                               if (strncmp
 -                                                   (tcon->ses->userName,
 -                                                    userName,
 -                                                    MAX_USERNAME_SIZE) == 0) {
 -                                                       read_unlock(&GlobalSMBSeslock);
 -                                                       /* matched smb session
 -                                                       (user name */
 -                                                       return tcon;
 -                                               }
 -                                       }
 -                               }
 -                       }
 -               }
 +               if (!tcon->ses || !tcon->ses->server)
 +                       continue;
 +
 +               old_ip = tcon->ses->server->addr.sockAddr.sin_addr.s_addr;
 +               cFYI(1, ("old ip addr: %x == new ip %x ?",
 +                       old_ip, new_target_ip_addr));
 +
 +               if (old_ip != new_target_ip_addr)
 +                       continue;
 +
 +               /* BB lock tcon, server and tcp session and increment use count here? */
 +               /* found a match on the TCP session */
 +               /* BB check if reconnection needed */
 +               cFYI(1, ("IP match, old UNC: %s new: %s",
 +                       tcon->treeName, uncName));
 +
 +               if (strncmp(tcon->treeName, uncName, MAX_TREE_SIZE))
 +                       continue;
 +
 +               cFYI(1, ("and old usr: %s new: %s",
 +                       tcon->treeName, uncName));
 +
 +               if (strncmp(tcon->ses->userName, userName, MAX_USERNAME_SIZE))
 +                       continue;
 +
 +               /* matched smb session (user name) */
 +               read_unlock(&GlobalSMBSeslock);
 +               return tcon;
        }
 +
        read_unlock(&GlobalSMBSeslock);
        return NULL;

}

--

Signature · 3 lines
Thanks,

Steve
#4 lore raw
In reply to Cyrill Gorcunov

This looks like it would fail in the ipv6 case - because target_ip_addr (the ipv4 address) would be null and it would exit before checking.

Quoted 86 lines · Cyrill Gorcunov

This patch is to remove too indented code in cifs_find_tcp_session.
Also memcmp was used wrongly - we would have found the session which IP6 addresses didn't match.

---

Index: linux-2.6.git/fs/cifs/connect.c
===================================================================
--- linux-2.6.git.orig/fs/cifs/connect.c 2008-05-01 19:02:51.000000000 +0400
+++ linux-2.6.git/fs/cifs/connect.c 2008-05-01 19:36:54.000000000 +0400
@@ -1318,42 +1318,44 @@ cifs_parse_mount_options(char *options,

static struct cifsSesInfo * cifs_find_tcp_session(struct in_addr *target_ip_addr,
- struct in6_addr *target_ip6_addr,
- char *userName, struct TCP_Server_Info **psrvTcp)
+ struct in6_addr *target_ip6_addr,
+ char *userName, struct TCP_Server_Info **psrvTcp)

  {
        struct list_head *tmp;
        struct cifsSesInfo *ses;
 +
        *psrvTcp = NULL;

- read_lock(&GlobalSMBSeslock);

+ if (!target_ip_addr)
+ return NULL;
+

 +       read_lock(&GlobalSMBSeslock);
        list_for_each(tmp, &GlobalSMBSessionList) {
                ses = list_entry(tmp, struct cifsSesInfo, cifsSessionList);
 -               if (ses->server) {
 -                       if ((target_ip_addr &&
 -                               (ses->server->addr.sockAddr.sin_addr.s_addr
 -                                 == target_ip_addr->s_addr)) || (target_ip6_addr
 -                               && memcmp(&ses->server->addr.sockAddr6.sin6_addr,
 -                                       target_ip6_addr, sizeof(*target_ip6_addr)))) {
 -                               /* BB lock server and tcp session and increment
 -                                     use count here?? */
 -
 -                               /* found a match on the TCP session */
 -                               *psrvTcp = ses->server;
 -
 -                               /* BB check if reconnection needed */
 -                               if (strncmp
 -                                   (ses->userName, userName,
 -                                    MAX_USERNAME_SIZE) == 0){
 -                                       read_unlock(&GlobalSMBSeslock);
 -                                       /* Found exact match on both TCP and
 -                                          SMB sessions */
 -                                       return ses;
 -                               }
 -                       }
 -               }
 -               /* else tcp and smb sessions need reconnection */
 +               if (!ses->server)
 +                       continue;
 +
 +               if (ses->server->addr.sockAddr.sin_addr.s_addr != target_ip_addr->s_addr ||
 +                   memcmp(&ses->server->addr.sockAddr6.sin6_addr,
 +                          target_ip6_addr, sizeof(*target_ip6_addr)))
 +                       continue;
 +
 +               /* BB lock server and tcp session and increment
 +                  use count here?? */
 +
 +               /* found a match on the TCP session */
 +               *psrvTcp = ses->server;
 +
 +               /* BB check if reconnection needed */
 +               if (strncmp(ses->userName, userName, MAX_USERNAME_SIZE))
 +                       continue;
 +
 +               /* Found exact match on both TCP and SMB sessions */
 +               read_unlock(&GlobalSMBSeslock);
 +               return ses;
        }
        read_unlock(&GlobalSMBSeslock);
 +
        return NULL;

}

--

Signature · 3 lines
Thanks,

Steve
#5 lore raw
Quoted 98 lines · Steve French

This looks like it would fail in the ipv6 case - because
target_ip_addr (the ipv4 address) would be null and it would exit before checking.

Quoted 81 lines · Cyrill Gorcunov

This patch is to remove too indented code in cifs_find_tcp_session.
Also memcmp was used wrongly - we would have found the session which IP6 addresses didn't match.

---

Index: linux-2.6.git/fs/cifs/connect.c
===================================================================
--- linux-2.6.git.orig/fs/cifs/connect.c 2008-05-01 19:02:51.000000000 +0400
+++ linux-2.6.git/fs/cifs/connect.c 2008-05-01 19:36:54.000000000 +0400
@@ -1318,42 +1318,44 @@ cifs_parse_mount_options(char *options,

static struct cifsSesInfo * cifs_find_tcp_session(struct in_addr *target_ip_addr,
- struct in6_addr *target_ip6_addr,
- char *userName, struct TCP_Server_Info **psrvTcp)
+ struct in6_addr *target_ip6_addr,
+ char *userName, struct TCP_Server_Info **psrvTcp)

  {
        struct list_head *tmp;
        struct cifsSesInfo *ses;
 +
        *psrvTcp = NULL;

- read_lock(&GlobalSMBSeslock);

+ if (!target_ip_addr)
+ return NULL;
+

 +       read_lock(&GlobalSMBSeslock);
        list_for_each(tmp, &GlobalSMBSessionList) {
                ses = list_entry(tmp, struct cifsSesInfo, cifsSessionList);
 -               if (ses->server) {
 -                       if ((target_ip_addr &&
 -                               (ses->server->addr.sockAddr.sin_addr.s_addr
 -                                 == target_ip_addr->s_addr)) || (target_ip6_addr
 -                               && memcmp(&ses->server->addr.sockAddr6.sin6_addr,
 -                                       target_ip6_addr, sizeof(*target_ip6_addr)))) {
 -                               /* BB lock server and tcp session and increment
 -                                     use count here?? */
 -
 -                               /* found a match on the TCP session */
 -                               *psrvTcp = ses->server;
 -
 -                               /* BB check if reconnection needed */
 -                               if (strncmp
 -                                   (ses->userName, userName,
 -                                    MAX_USERNAME_SIZE) == 0){
 -                                       read_unlock(&GlobalSMBSeslock);
 -                                       /* Found exact match on both TCP and
 -                                          SMB sessions */
 -                                       return ses;
 -                               }
 -                       }
 -               }
 -               /* else tcp and smb sessions need reconnection */
 +               if (!ses->server)
 +                       continue;
 +
 +               if (ses->server->addr.sockAddr.sin_addr.s_addr != target_ip_addr->s_addr ||
 +                   memcmp(&ses->server->addr.sockAddr6.sin6_addr,
 +                          target_ip6_addr, sizeof(*target_ip6_addr)))
 +                       continue;
 +
 +               /* BB lock server and tcp session and increment
 +                  use count here?? */
 +
 +               /* found a match on the TCP session */
 +               *psrvTcp = ses->server;
 +
 +               /* BB check if reconnection needed */
 +               if (strncmp(ses->userName, userName, MAX_USERNAME_SIZE))
 +                       continue;
 +
 +               /* Found exact match on both TCP and SMB sessions */
 +               read_unlock(&GlobalSMBSeslock);
 +               return ses;
        }
        read_unlock(&GlobalSMBSeslock);
 +
        return NULL;
Quoted 5 lines

}

--

Quoted 5 lines

--
Thanks,

Steve

Ah, indeed! Thanks, Steve, I'm really sorry for this. Will remake it.

Andrew, could you drop it from -mm please?

#6 lore raw
In reply to Steve French
Quoted 4 lines · Steve French

This looks like it would fail in the ipv6 case - because
target_ip_addr (the ipv4 address) would be null and it would exit before checking.

Steve, could you check an updated version, please

---
From: Cyrill Gorcunov <[email protected]>
Subject: [PATCH] cifs - cifs_find_tcp_session fix/cleanup v2

This patch cleans up cifs_find_tcp_session so it become less indented. Also the error of skipping IPv6 matched addresses fixed.

---

fs/cifs/connect.c +26 -25
@@ -1318,42 +1318,43 @@ cifs_parse_mount_options(char *options, 
 
 static struct cifsSesInfo *
 cifs_find_tcp_session(struct in_addr *target_ip_addr,
-		struct in6_addr *target_ip6_addr,
-		 char *userName, struct TCP_Server_Info **psrvTcp)
+		      struct in6_addr *target_ip6_addr,
+		      char *userName, struct TCP_Server_Info **psrvTcp)
 {
 	struct list_head *tmp;
 	struct cifsSesInfo *ses;
+
 	*psrvTcp = NULL;
-	read_lock(&GlobalSMBSeslock);
 
+	read_lock(&GlobalSMBSeslock);
 	list_for_each(tmp, &GlobalSMBSessionList) {
 		ses = list_entry(tmp, struct cifsSesInfo, cifsSessionList);
-		if (ses->server) {
-			if ((target_ip_addr &&
-				(ses->server->addr.sockAddr.sin_addr.s_addr
-				  == target_ip_addr->s_addr)) || (target_ip6_addr
-				&& memcmp(&ses->server->addr.sockAddr6.sin6_addr,
-					target_ip6_addr, sizeof(*target_ip6_addr)))) {
-				/* BB lock server and tcp session and increment
-				      use count here?? */
-
-				/* found a match on the TCP session */
-				*psrvTcp = ses->server;
-
-				/* BB check if reconnection needed */
-				if (strncmp
-				    (ses->userName, userName,
-				     MAX_USERNAME_SIZE) == 0){
-					read_unlock(&GlobalSMBSeslock);
-					/* Found exact match on both TCP and
-					   SMB sessions */
-					return ses;
-				}
-			}
+		if (!ses->server)
+			continue;
+
+		if (target_ip_addr &&
+		    ses->server->addr.sockAddr.sin_addr.s_addr != target_ip_addr->s_addr)
+				continue;
+		else if (target_ip6_addr &&
+			 memcmp(&ses->server->addr.sockAddr6.sin6_addr,
+				target_ip6_addr, sizeof(*target_ip6_addr)))
+				continue;
+		/* BB lock server and tcp session and increment use count here?? */
+
+		/* found a match on the TCP session */
+		*psrvTcp = ses->server;
+
+		/* BB check if reconnection needed */
+		if (strncmp(ses->userName, userName, MAX_USERNAME_SIZE) == 0) {
+			read_unlock(&GlobalSMBSeslock);
+			/* Found exact match on both TCP and
+			   SMB sessions */
+			return ses;
 		}
 		/* else tcp and smb sessions need reconnection */
 	}
 	read_unlock(&GlobalSMBSeslock);
+
 	return NULL;
 }
 
#7 lore raw

reviewed and checked in.

Quoted 8 lines · Cyrill Gorcunov
Quoted 4 lines · Steve French

This looks like it would fail in the ipv6 case - because
target_ip_addr (the ipv4 address) would be null and it would exit before checking.

Steve, could you check an updated version, please

--
Thanks,

Steve