This is protect destroying fcoe interface while used
as root filesystem.

Adds -r option to accept root interface name then sets up
rootfs flag for its associated fcoe_ports, that flag
is later used to ignore any subsequent FCOE_DESTROY
operation on root interface.

Signed-off-by: Vasu Dev <[email protected]>
---

 fcoemon.c |   50 +++++++++++++++++++++++++++++++++++++-------------
 fcoemon.h |    1 -
 2 files changed, 37 insertions(+), 14 deletions(-)

diff --git a/fcoemon.c b/fcoemon.c
index ffe39ef..a0edade 100644
--- a/fcoemon.c
+++ b/fcoemon.c
@@ -111,6 +111,7 @@ struct fcoe_port {
        int fcoe_enable;
        int dcb_required;
        int auto_vlan;
+       int rootif;
 
        /* following track data required to manage FCoE interface state */
        enum fcp_action action;      /* current state */
@@ -173,6 +174,7 @@ static int fcm_fip_socket;
  */
 static struct option fcm_options[] = {
        {"debug", 0, NULL, 'd'},
+       {"rootif", 1, NULL, 'r'},
        {"syslog", 0, NULL, 's'},
        {"exec", 1, NULL, 'e'},
        {"foreground", 0, NULL, 'f'},
@@ -294,11 +296,11 @@ static struct fcoe_port *alloc_fcoe_port(char *ifname)
        return p;
 }
 
-static int fcm_read_config_files(void)
+static int fcm_read_config_files(char *rootif)
 {
        char file[80];
        FILE *fp;
-       char val[CONFIG_MAX_VAL_LEN + 1];
+       char val[CONFIG_MAX_VAL_LEN + 1], *ifname;
        DIR *dir;
        struct dirent *dp;
        struct fcoe_port *curr = NULL;
@@ -327,13 +329,18 @@ static int fcm_read_config_files(void)
                             strlen(DEF_CFG_FILE)))
                        continue;
 
-               next = alloc_fcoe_port(dp->d_name + 4);
-
+               ifname = dp->d_name + 4;
+               next = alloc_fcoe_port(ifname);
                if (!next) {
                        FCM_LOG_ERR(errno, "failed to allocate fcoe_port %s",
                                dp->d_name);
                        continue;
                }
+
+               /* ROOT IF */
+               if (!strncmp(rootif, ifname, strlen(ifname)))
+                       next->rootif = 1;
+
                strncpy(file, CONFIG_DIR "/", sizeof(file));
                strncat(file, dp->d_name, sizeof(file) - strlen(file));
                fp = fopen(file, "r");
@@ -490,10 +497,11 @@ static int fcm_link_init(void)
 
 static struct fcoe_port *fcm_port_create(char *ifname, int cmd);
 
-void fcm_new_vlan(int ifindex, int vid)
+void fcm_new_vlan(struct fcoe_port *p, int ifindex, int vid)
 {
        char real_name[IFNAMSIZ];
        char vlan_name[IFNAMSIZ];
+       struct fcoe_port *vp;
 
        FCM_LOG_DBG("Auto VLAN Found FCF on VID %d\n", vid);
 
@@ -503,7 +511,9 @@ void fcm_new_vlan(int ifindex, int vid)
                vlan_create(ifindex, vid, vlan_name);
        }
        rtnl_set_iff_up(0, vlan_name);
-       fcm_port_create(vlan_name, FCP_CREATE_IF);
+       vp = fcm_port_create(vlan_name, FCP_CREATE_IF);
+       if (vp)
+               vp->rootif = p->rootif;
 }
 
 
@@ -545,7 +555,7 @@ int fcm_vlan_disc_handler(struct fiphdr *fh, struct 
sockaddr_ll *sa, void *arg)
                                break;
                        }
                        vid = ntohs(((struct fip_tlv_vlan *)tlv)->vlan);
-                       fcm_new_vlan(sa->sll_ifindex, vid);
+                       fcm_new_vlan(p, sa->sll_ifindex, vid);
                        break;
                default:
                        /* unexpected or unrecognized descriptor */
@@ -1069,9 +1079,9 @@ static int fcm_link_buf_check(size_t read_len)
        return 0;
 }
 
-static void fcm_fcoe_init(void)
+static void fcm_fcoe_init(char *rootif)
 {
-       if (fcm_read_config_files())
+       if (fcm_read_config_files(rootif))
                exit(1);
 }
 
@@ -1247,7 +1257,11 @@ static void fcm_cleanup(void)
 
        for (curr = fcoe_config.port; curr; curr = next) {
                FCM_LOG_DBG("OP: DESTROY %s\n", curr->ifname);
-               fcm_fcoe_if_action(FCOE_DESTROY,  curr->ifname);
+               if (curr->rootif)
+                       FCM_LOG_DBG("OP: skipping DESTROY on root i/f %s\n",
+                                   curr->ifname);
+               else
+                       fcm_fcoe_if_action(FCOE_DESTROY,  curr->ifname);
                next = curr->next;
                free(curr);
        }
@@ -1999,7 +2013,12 @@ static void fcm_fcoe_action(struct fcm_netif *ff, struct 
fcoe_port *p)
                break;
        case FCP_DESTROY_IF:
                FCM_LOG_DBG("OP: DESTROY %s\n", p->ifname);
-               rc = fcm_fcoe_if_action(FCOE_DESTROY, ifname);
+               if (p->rootif) {
+                       FCM_LOG_DBG("OP: DESTROY not allowed on root i/f %s\n",
+                                   p->ifname);
+                       rc = EINVALARG;
+               } else
+                       rc = fcm_fcoe_if_action(FCOE_DESTROY, ifname);
                break;
        case FCP_ENABLE_IF:
                FCM_LOG_DBG("OP: ENABLE %s\n", p->ifname);
@@ -2218,6 +2237,7 @@ static void fcm_usage(void)
        printf("Usage: %s\n"
               "\t [-f|--foreground]\n"
               "\t [-d|--debug]\n"
+              "\t [-r|--rootif ] <ethX>\n"
               "\t [-s|--syslog]\n"
               "\t [-v|--version]\n"
               "\t [-h|--help]\n\n", progname);
@@ -2526,6 +2546,7 @@ int main(int argc, char **argv)
 {
        struct fcm_srv_info srv_info;
        struct sigaction sig;
+       char rootif[IFNAMSIZ] = { '\0' };
        int fcm_fg = 0;
        int rc;
        int c;
@@ -2537,7 +2558,7 @@ int main(int argc, char **argv)
        sa_log_flags = 0;
        openlog(sa_log_prefix, LOG_CONS, LOG_DAEMON);
 
-       while ((c = getopt_long(argc, argv, "fdhv",
+       while ((c = getopt_long(argc, argv, "fdr:hv",
                                fcm_options, NULL)) != -1) {
                switch (c) {
                case 'f':
@@ -2547,6 +2568,9 @@ int main(int argc, char **argv)
                        fcoe_config.debug = 1;
                        enable_debug_log(1);
                        break;
+               case 'r':
+                       strncpy(rootif, optarg, IFNAMSIZ);
+                       break;
                case 's':
                        fcoe_config.use_syslog = 1;
                        enable_syslog(1);
@@ -2614,7 +2638,7 @@ int main(int argc, char **argv)
                exit(1);
        }
 
-       fcm_fcoe_init();
+       fcm_fcoe_init(rootif);
        fcm_link_init();        /* NETLINK_ROUTE protocol */
        fcm_dcbd_init();
        fcm_vlan_disc_init();
diff --git a/fcoemon.h b/fcoemon.h
index 9917d76..385d1f9 100644
--- a/fcoemon.h
+++ b/fcoemon.h
@@ -155,7 +155,6 @@ struct fcm_netif_head fcm_netif_head;
 
 static void fcm_dcbd_init(void);
 static void fcm_dcbd_shutdown(void);
-static void fcm_fcoe_init(void);
 static struct fcm_netif *fcm_netif_lookup(char *);
 static struct fcm_netif *fcm_netif_lookup_create(char *);
 static int fcm_link_init(void);

_______________________________________________
devel mailing list
[email protected]
http://www.open-fcoe.org/mailman/listinfo/devel

Reply via email to