}
return obd;
}
-EXPORT_SYMBOL(obd_device_alloc);
static void obd_device_free(struct obd_device *obd)
{
struct obd_device *obd = exp->exp_obd;
ENTRY;
- LASSERT (cfs_atomic_read(&exp->exp_refcount) == 0);
+ LASSERT_ATOMIC_ZERO(&exp->exp_refcount);
CDEBUG(D_IOCTL, "destroying export %p/%s for %s\n", exp,
exp->exp_client_uuid.uuid, obd->obd_name);
void class_export_put(struct obd_export *exp)
{
LASSERT(exp != NULL);
+ LASSERT_ATOMIC_GT_LT(&exp->exp_refcount, 0, 0x5a5a5a);
CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", exp,
cfs_atomic_read(&exp->exp_refcount) - 1);
- LASSERT(cfs_atomic_read(&exp->exp_refcount) > 0);
- LASSERT(cfs_atomic_read(&exp->exp_refcount) < 0x5a5a5a);
if (cfs_atomic_dec_and_test(&exp->exp_refcount)) {
LASSERT(!cfs_list_empty(&exp->exp_obd_chain));
CDEBUG(D_IOCTL, "destroying import %p for %s\n", imp,
imp->imp_obd->obd_name);
- LASSERT(cfs_atomic_read(&imp->imp_refcount) == 0);
+ LASSERT_ATOMIC_ZERO(&imp->imp_refcount);
ptlrpc_put_connection_superhack(imp->imp_connection);
struct obd_import *class_import_get(struct obd_import *import)
{
- LASSERT(cfs_atomic_read(&import->imp_refcount) >= 0);
- LASSERT(cfs_atomic_read(&import->imp_refcount) < 0x5a5a5a);
cfs_atomic_inc(&import->imp_refcount);
CDEBUG(D_INFO, "import %p refcount=%d obd=%s\n", import,
cfs_atomic_read(&import->imp_refcount),
{
ENTRY;
- LASSERT(cfs_atomic_read(&imp->imp_refcount) > 0);
- LASSERT(cfs_atomic_read(&imp->imp_refcount) < 0x5a5a5a);
LASSERT(cfs_list_empty(&imp->imp_zombie_chain));
+ LASSERT_ATOMIC_GE_LT(&imp->imp_refcount, 0, 0x5a5a5a);
CDEBUG(D_INFO, "import %p refcount=%d obd=%s\n", imp,
cfs_atomic_read(&imp->imp_refcount) - 1,
}
EXPORT_SYMBOL(obd_exports_barrier);
+/* Total amount of zombies to be destroyed */
+static int zombies_count = 0;
+
/**
* kill zombie imports and exports
*/
cfs_spin_unlock(&obd_zombie_impexp_lock);
- if (import != NULL)
+ if (import != NULL) {
class_import_destroy(import);
+ cfs_spin_lock(&obd_zombie_impexp_lock);
+ zombies_count--;
+ cfs_spin_unlock(&obd_zombie_impexp_lock);
+ }
- if (export != NULL)
+ if (export != NULL) {
class_export_destroy(export);
+ cfs_spin_lock(&obd_zombie_impexp_lock);
+ zombies_count--;
+ cfs_spin_unlock(&obd_zombie_impexp_lock);
+ }
cfs_cond_resched();
} while (import != NULL || export != NULL);
int rc;
cfs_spin_lock(&obd_zombie_impexp_lock);
- rc = cfs_list_empty(&obd_zombie_imports) &&
- cfs_list_empty(&obd_zombie_exports) &&
+ rc = (zombies_count == 0) &&
!cfs_test_bit(OBD_ZOMBIE_STOP, &obd_zombie_flags);
-
cfs_spin_unlock(&obd_zombie_impexp_lock);
RETURN(rc);
cfs_list_del_init(&exp->exp_obd_chain);
cfs_spin_unlock(&exp->exp_obd->obd_dev_lock);
cfs_spin_lock(&obd_zombie_impexp_lock);
+ zombies_count++;
cfs_list_add(&exp->exp_obd_chain, &obd_zombie_exports);
cfs_spin_unlock(&obd_zombie_impexp_lock);
LASSERT(imp->imp_sec == NULL);
cfs_spin_lock(&obd_zombie_impexp_lock);
LASSERT(cfs_list_empty(&imp->imp_zombie_chain));
+ zombies_count++;
cfs_list_add(&imp->imp_zombie_chain, &obd_zombie_imports);
cfs_spin_unlock(&obd_zombie_impexp_lock);
LASSERT(!cfs_test_bit(OBD_ZOMBIE_STOP, &obd_zombie_flags));
cfs_spin_lock(&obd_zombie_impexp_lock);
- rc = cfs_list_empty(&obd_zombie_imports) &&
- cfs_list_empty(&obd_zombie_exports);
+ rc = (zombies_count == 0);
cfs_spin_unlock(&obd_zombie_impexp_lock);
return rc;
}
#endif
}
+/***** Kernel-userspace comm helpers *******/
+
+/* Get length of entire message, including header */
+int kuc_len(int payload_len)
+{
+ return sizeof(struct kuc_hdr) + payload_len;
+}
+EXPORT_SYMBOL(kuc_len);
+
+/* Get a pointer to kuc header, given a ptr to the payload
+ * @param p Pointer to payload area
+ * @returns Pointer to kuc header
+ */
+struct kuc_hdr * kuc_ptr(void *p)
+{
+ struct kuc_hdr *lh = ((struct kuc_hdr *)p) - 1;
+ LASSERT(lh->kuc_magic == KUC_MAGIC);
+ return lh;
+}
+EXPORT_SYMBOL(kuc_ptr);
+
+/* Test if payload is part of kuc message
+ * @param p Pointer to payload area
+ * @returns boolean
+ */
+int kuc_ispayload(void *p)
+{
+ struct kuc_hdr *kh = ((struct kuc_hdr *)p) - 1;
+
+ if (kh->kuc_magic == KUC_MAGIC)
+ return 1;
+ else
+ return 0;
+}
+EXPORT_SYMBOL(kuc_ispayload);
+
+/* Alloc space for a message, and fill in header
+ * @return Pointer to payload area
+ */
+void *kuc_alloc(int payload_len, int transport, int type)
+{
+ struct kuc_hdr *lh;
+ int len = kuc_len(payload_len);
+
+ OBD_ALLOC(lh, len);
+ if (lh == NULL)
+ return ERR_PTR(-ENOMEM);
+
+ lh->kuc_magic = KUC_MAGIC;
+ lh->kuc_transport = transport;
+ lh->kuc_msgtype = type;
+ lh->kuc_msglen = len;
+
+ return (void *)(lh + 1);
+}
+EXPORT_SYMBOL(kuc_alloc);
+
+/* Takes pointer to payload area */
+inline void kuc_free(void *p, int payload_len)
+{
+ struct kuc_hdr *lh = kuc_ptr(p);
+ OBD_FREE(lh, kuc_len(payload_len));
+}
+EXPORT_SYMBOL(kuc_free);
+
+
+