MCPcopy Create free account
hub / github.com/F-Stack/f-stack / vhost_blk_ctrlr_construct

Function vhost_blk_ctrlr_construct

dpdk/examples/vhost_blk/vhost_blk.c:786–838  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

784}
785
786static struct vhost_blk_ctrlr *
787vhost_blk_ctrlr_construct(const char *ctrlr_name)
788{
789 int ret;
790 struct vhost_blk_ctrlr *ctrlr;
791 char *path;
792 char cwd[PATH_MAX];
793
794 /* always use current directory */
795 path = getcwd(cwd, PATH_MAX);
796 if (!path) {
797 fprintf(stderr, "Cannot get current working directory\n");
798 return NULL;
799 }
800 snprintf(dev_pathname, sizeof(dev_pathname), "%s/%s", path, ctrlr_name);
801
802 unlink(dev_pathname);
803
804 if (rte_vhost_driver_register(dev_pathname, 0) != 0) {
805 fprintf(stderr, "Socket %s already exists\n", dev_pathname);
806 return NULL;
807 }
808
809 ret = rte_vhost_driver_set_features(dev_pathname, VHOST_BLK_FEATURES);
810 if (ret != 0) {
811 fprintf(stderr, "Set vhost driver features failed\n");
812 rte_vhost_driver_unregister(dev_pathname);
813 return NULL;
814 }
815
816 /* set vhost user protocol features */
817 vhost_dev_install_rte_compat_hooks(dev_pathname);
818
819 ctrlr = rte_zmalloc(NULL, sizeof(*ctrlr), RTE_CACHE_LINE_SIZE);
820 if (!ctrlr) {
821 rte_vhost_driver_unregister(dev_pathname);
822 return NULL;
823 }
824
825 /* hardcoded block device information with 128MiB */
826 ctrlr->bdev = vhost_blk_bdev_construct("malloc0", "vhost_blk_malloc0",
827 4096, 32768, 0);
828 if (!ctrlr->bdev) {
829 rte_free(ctrlr);
830 rte_vhost_driver_unregister(dev_pathname);
831 return NULL;
832 }
833
834 rte_vhost_driver_callback_register(dev_pathname,
835 &vhost_blk_device_ops);
836
837 return ctrlr;
838}
839
840static void
841vhost_blk_ctrlr_destroy(struct vhost_blk_ctrlr *ctrlr)

Callers 1

mainFunction · 0.85

Calls 9

snprintfFunction · 0.85
rte_zmallocFunction · 0.85
vhost_blk_bdev_constructFunction · 0.85
rte_freeFunction · 0.85

Tested by

no test coverage detected