* (such as VFS logic) that will not compile easily in userland.
*/
#ifdef _KERNEL
+#ifdef HAVE_ZPL
/*
* Needed to close a small window in zfs_znode_move() that allows the zfsvfs to
* be freed before it can be safely accessed.
dmu_tx_commit(tx);
return (0);
}
+#endif /* HAVE_ZPL */
void
zfs_create_fs(objset_t *os, cred_t *cr, nvlist_t *zplprops, dmu_tx_t *tx)
{
- zfsvfs_t zfsvfs;
uint64_t moid, obj, sa_obj, version;
uint64_t sense = ZFS_CASE_SENSITIVE;
uint64_t norm = 0;
nvpair_t *elem;
int error;
+#ifdef HAVE_ZPL
+ zfsvfs_t zfsvfs;
int i;
znode_t *rootzp = NULL;
vnode_t *vp;
vattr_t vattr;
znode_t *zp;
zfs_acl_ids_t acl_ids;
+#else
+ timestruc_t now;
+ dmu_buf_t *db;
+ znode_phys_t *pzp;
+#endif /* HAVE_ZPL */
/*
* First attempt to create master node.
error = zap_add(os, moid, ZFS_UNLINKED_SET, 8, 1, &obj, tx);
ASSERT(error == 0);
+#ifdef HAVE_ZPL
/*
* Create root znode. Create minimal znode/vnode/zfsvfs
* to allow zfs_mknode to work.
if (sense == ZFS_CASE_INSENSITIVE || sense == ZFS_CASE_MIXED)
zfsvfs.z_norm |= U8_TEXTPREP_TOUPPER;
+ /* XXX - This must be destroyed but I'm not quite sure yet so
+ * I'm just annotating that fact when it's an issue. -Brian */
mutex_init(&zfsvfs.z_znodes_lock, NULL, MUTEX_DEFAULT, NULL);
list_create(&zfsvfs.z_all_znodes, sizeof (znode_t),
offsetof(znode_t, z_link_node));
ZTOV(rootzp)->v_count = 0;
sa_handle_destroy(rootzp->z_sa_hdl);
kmem_cache_free(znode_cache, rootzp);
+ error = zfs_create_share_dir(&zfsvfs, tx);
+ for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
+ mutex_destroy(&zfsvfs.z_hold_mtx[i]);
+#else
/*
- * Create shares directory
+ * Create root znode with code free of VFS dependencies
*/
+ obj = zap_create_norm(os, norm, DMU_OT_DIRECTORY_CONTENTS,
+ DMU_OT_ZNODE, sizeof (znode_phys_t), tx);
- error = zfs_create_share_dir(&zfsvfs, tx);
+ VERIFY(0 == dmu_bonus_hold(os, obj, FTAG, &db));
+ dmu_buf_will_dirty(db, tx);
+ /*
+ * Initialize the znode physical data to zero.
+ */
+ ASSERT(db->db_size >= sizeof (znode_phys_t));
+ bzero(db->db_data, db->db_size);
+ pzp = db->db_data;
+
+ if (USE_FUIDS(version, os))
+ pzp->zp_flags = ZFS_ARCHIVE | ZFS_AV_MODIFIED;
+
+ pzp->zp_size = 2; /* "." and ".." */
+ pzp->zp_links = 2;
+ pzp->zp_parent = obj;
+ pzp->zp_gen = dmu_tx_get_txg(tx);
+ pzp->zp_mode = S_IFDIR | 0755;
+ pzp->zp_flags = ZFS_ACL_TRIVIAL;
+
+ gethrestime(&now);
+
+ ZFS_TIME_ENCODE(&now, pzp->zp_crtime);
+ ZFS_TIME_ENCODE(&now, pzp->zp_ctime);
+ ZFS_TIME_ENCODE(&now, pzp->zp_atime);
+ ZFS_TIME_ENCODE(&now, pzp->zp_mtime);
+
+ error = zap_add(os, moid, ZFS_ROOT_OBJ, 8, 1, &obj, tx);
ASSERT(error == 0);
- for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
- mutex_destroy(&zfsvfs.z_hold_mtx[i]);
+ dmu_buf_rele(db, FTAG);
+#endif /* HAVE_ZPL */
}
#endif /* _KERNEL */
dmu_object_info_from_db(*db, &doi);
if ((doi.doi_bonus_type != DMU_OT_SA &&
doi.doi_bonus_type != DMU_OT_ZNODE) ||
- doi.doi_bonus_type == DMU_OT_ZNODE &&
- doi.doi_bonus_size < sizeof (znode_phys_t)) {
+ (doi.doi_bonus_type == DMU_OT_ZNODE &&
+ doi.doi_bonus_size < sizeof (znode_phys_t))) {
sa_buf_rele(*db, FTAG);
return (ENOTSUP);
}
zfs_release_sa_handle(hdl, db);
return (error);
}
+
+#if defined(_KERNEL) && defined(HAVE_SPL)
+EXPORT_SYMBOL(zfs_create_fs);
+EXPORT_SYMBOL(zfs_obj_to_path);
+#endif