From: Vladislav B. <vs...@vl...> - 2025-03-25 19:46:31
|
Hi, There is a code example at https://github.com/SCST-project/scst/tree/master/usr/fileio, you can look how it works. Vlad On 25.03.25 17:09, Joshua Colletta wrote: > Hi all, > > New to the mailing list, so let me know if there is a better place to > ask these sorts of questions in the future. > > I am new to SCST, my project is essentially a modified Virtual Tape > Library. I am attempting to use the scst_user handler to "pump" scsi > commands from the kernels interface up to the userspace, where an > awaiting Cpp codebase will action them. > > My problem however, is thus: > > I cannot get device registration to work on the code end. > > As I understand it, the code itself has to report to the backend that it > wishes to init the emulated device within the userspace. In order to do > this I am trying to follow the scst_user docs as closely as possible. > > I am, however, running into: "Failed to register SCST device: Errno=22 > (Invalid Argument) when calling my ioctl(scst_fd, SCST_USER_REGISTER_DEVICE) > > Code snippet below: > > int TapeEmulationCore::init_SCSI_User_Interface(int &scst_fd) { > // Open SCST user interface > scst_fd = open("/dev/scst_user", O_RDWR); > if (scst_fd < 0) { > std::cerr << "Failed to open SCST User interface: /dev/scst_user\n"; > return 1; > } > // Ensure the device descriptor is zeroed and properly aligned > scst_user_dev_desc dev; > std::cout << "Size of dev:" << sizeof(dev) << std::endl; > memset(&dev, 0, sizeof(dev));// safe init > > // Ensure version/license strings are in user-space memory > alignas(8) char version_str[] = DEV_USER_VERSION; > alignas(8) char license_str[] = "GPL"; > > // Assign required string pointers (as aligned_u64) > dev.version_str = reinterpret_cast<aligned_u64>(version_str); > dev.license_str = reinterpret_cast<aligned_u64>(license_str); > > // Assign device identity > strncpy(dev.name, "my_virtual_tape", sizeof(dev.name) - 1); > strncpy(dev.sgv_name, dev.name, sizeof(dev.sgv_name) - 1);// use same > name for SGV cache > > // Basic device config > dev.type = TYPE_TAPE; > dev.block_size = 512; > > // SGV memory/cache config (basic, non-shared, default pooling) > dev.sgv_shared = 0; > dev.sgv_disable_clustered_pool = 0; > dev.sgv_single_alloc_pages = 0; > dev.sgv_purge_interval = 0; > > // Main device behavior options > dev.opt.parse_type = SCST_USER_PARSE_CALL; > dev.opt.on_free_cmd_type = SCST_USER_ON_FREE_CMD_IGNORE; > dev.opt.memory_reuse_type = SCST_USER_MEM_NO_REUSE; > dev.opt.partial_transfers_type = SCST_USER_PARTIAL_TRANSFERS_NOT_SUPPORTED; > dev.opt.partial_len = 0; > dev.opt.tst = 0; > dev.opt.queue_alg = 0; > dev.opt.tas = 0; > dev.opt.swp = 0; > dev.opt.d_sense = 0; > dev.opt.has_own_order_mgmt = 0; > > std::cout << "Size of filled dev: " << sizeof(dev) << std::endl; > > > std::cout << "---- Dumping scst_user_dev_desc ----" << std::endl; > std::cout << "version_str: " << reinterpret_cast<const > char*>(dev.version_str) << std::endl; > std::cout << "license_str: " << reinterpret_cast<const > char*>(dev.license_str) << std::endl; > std::cout << "name: " << dev.name << std::endl; > std::cout << "sgv_name: " << dev.sgv_name << std::endl; > std::cout << "type: " << (int)dev.type << std::endl; > std::cout << "block_size: " << dev.block_size << std::endl; > std::cout << "sgv_shared: " << (int)dev.sgv_shared << std::endl; > std::cout << "disable_pool: " << (int)dev.sgv_disable_clustered_pool << > std::endl; > std::cout << "single_alloc_pages: " << dev.sgv_single_alloc_pages << > std::endl; > std::cout << "purge_interval: " << dev.sgv_purge_interval << std::endl; > std::cout << "has_own_order_mgmt: " << (int)dev.opt.has_own_order_mgmt > << std::endl; > std::cout << "opt.parse_type: " << (int)dev.opt.parse_type << std::endl; > std::cout << "opt.mem_reuse_type: " << (int)dev.opt.memory_reuse_type << > std::endl; > > // Register the device > if (ioctl(scst_fd, SCST_USER_REGISTER_DEVICE, &dev) < 0) { > std::cerr << "Failed to register SCST device: errno=" << errno << " (" > << strerror(errno) << ")" << "\n"; > close(scst_fd); > return 1; > } > > Which in returns the following: > > image.png > > I apologise for dumping code. It struck me that this was likely an > alignment problem? I was wondering if someone with experience with the > scst_user handler could help me? Or perhaps, if it's easier, had a > minimal setup example I could use as reference? > > Many thanks in advance, > > Josh Colletta > > > > > _______________________________________________ > Scst-devel mailing list > https://lists.sourceforge.net/lists/listinfo/scst-devel |