Whamcloud - gitweb
smash the HEAD with the contents of b_cmd. HEAD_PRE_CMD_SMASH and
[fs/lustre-release.git] / lustre / obdclass / lustre_peer.c
index 8298fc3..1e227e1 100644 (file)
@@ -42,6 +42,7 @@ struct uuid_nid_data {
         ptl_nid_t nid;
         char *uuid;
         __u32 nal;
+        ptl_handle_ni_t ni;
 };
 
 /* FIXME: This should probably become more elegant than a global linked list */
@@ -60,7 +61,8 @@ void class_exit_uuidlist(void)
         class_del_uuid(NULL);
 }
 
-int lustre_uuid_to_peer(char *uuid, __u32 *peer_nal, ptl_nid_t *peer_nid)
+int lustre_uuid_to_peer(char *uuid, 
+                        ptl_handle_ni_t *peer_ni, ptl_nid_t *peer_nid)
 {
         struct list_head *tmp;
 
@@ -72,7 +74,7 @@ int lustre_uuid_to_peer(char *uuid, __u32 *peer_nal, ptl_nid_t *peer_nid)
 
                 if (strcmp(data->uuid, uuid) == 0) {
                         *peer_nid = data->nid;
-                        *peer_nal = data->nal;
+                        *peer_ni = data->ni;
 
                         spin_unlock (&g_uuid_lock);
                         return 0;
@@ -85,6 +87,7 @@ int lustre_uuid_to_peer(char *uuid, __u32 *peer_nal, ptl_nid_t *peer_nid)
 
 int class_add_uuid(char *uuid, __u64 nid, __u32 nal)
 {
+        const ptl_handle_ni_t *nip;
         struct uuid_nid_data *data;
         int rc;
         int nob = strnlen (uuid, PAGE_SIZE) + 1;
@@ -92,21 +95,26 @@ int class_add_uuid(char *uuid, __u64 nid, __u32 nal)
         if (nob > PAGE_SIZE)
                 return -EINVAL;
 
+        nip = kportal_get_ni (nal);
+        if (nip == NULL) {
+                CERROR("get_ni failed: is the NAL module loaded?\n");
+                return -EIO;
+        }
+
         rc = -ENOMEM;
         OBD_ALLOC(data, sizeof(*data));
         if (data == NULL)
-                return -ENOMEM;
+                goto fail_0;
 
         OBD_ALLOC(data->uuid, nob);
-        if (data == NULL) {
-                OBD_FREE(data, sizeof(*data));
-                return -ENOMEM;
-        }
+        if (data == NULL)
+                goto fail_1;
 
         CDEBUG(D_INFO, "add uuid %s "LPX64" %u\n", uuid, nid, nal);
         memcpy(data->uuid, uuid, nob);
         data->nid = nid;
         data->nal = nal;
+        data->ni  = *nip;
 
         spin_lock (&g_uuid_lock);
 
@@ -115,6 +123,12 @@ int class_add_uuid(char *uuid, __u64 nid, __u32 nal)
         spin_unlock (&g_uuid_lock);
 
         return 0;
+
+ fail_1:
+        OBD_FREE (data, sizeof (*data));
+ fail_0:
+        kportal_put_ni (nal);
+        return (rc);
 }
 
 /* delete only one entry if uuid is specified, otherwise delete all */
@@ -150,6 +164,7 @@ int class_del_uuid (char *uuid)
 
                 list_del (&data->head);
 
+                kportal_put_ni (data->nal);
                 OBD_FREE(data->uuid, strlen(data->uuid) + 1);
                 OBD_FREE(data, sizeof(*data));
         } while (!list_empty (&deathrow));