libsmb2, meet samba

Jeremy Allison jra at samba.org
Wed Apr 26 00:09:45 UTC 2017


On Tue, Apr 25, 2017 at 04:26:48PM -0700, ronnie sahlberg via samba-technical wrote:
> Update. Start of unstructured brain dump:
> 
> 
> Libsmb2 is nearing its first official release. Which means it has all
> the features that QEMU and KODI (main consumers) need.
> Please have a look at my github repo.
> 
> 
> Libsmb2 is fully async and non-blocking.
> It does zero-copy for both READ and WRITE commands, in the sense that
> it reads/writes the application buffer directly to/from the socket
> without any memcpy() being done in the library itself.  True zero-copy
> will have to wait until RDMA support comes.
> 
> It also supports compounded requests making the common pattern of
> CREATE/do-something/CLOSE execute in a single roundtrip.
> This should make a lot of metadata operations fast-ish.
> 
> Not bloated yet, almost fitting in memory of a Sinclair Spectrum:
> $ ls -l lib/.libs/libsmb2.so.1.0.0
> -rwxrwxr-x. 1 sahlberg sahlberg 51816 Apr 25 16:05 lib/.libs/libsmb2.so.1.0.0
> 
> 
> No external dependencies outside from MIT and basic libc making it,
> very portable.
> As I am not fluent in Visual Studio I would welcome any help I can get
> to set up a proper VS project file.
> 
> 
> At this point I think the library is in a usable state and the API
> should be declared stable.
> Some features should still be added but as far as main consumers, i.e.
> QEMU and KODI, are concerned we
> are in a releasable state for 0.1 feature wise.
> 
> 
> I was chatting with Jeremy about features that would be nice to add
> after the 0.1 release and I would be happy to work with anyone
> that wants to contribute.
> My idea of such post 0.1 features would be :
> * krb5 support. Currently only gss-ntlmssp is supported but adding
> krb5 support should be trivial.
> * sing and seal.
> * visual studio 1* project files and support.
> * SET_INFO support
> * a simple cifs fuse module.
> * RDMA (this is probably not a near term goal)
> 
> 
> 
> Now, at the end, I just want to show what the compound API ended up
> looking like.
> Not too shabby me thinks.
> 
> Example of using the compound request API:
> ==================================
>         /* CREATE command */
>         memset(&cr_req, 0, sizeof(struct smb2_create_request));
>         cr_req.requested_oplock_level = SMB2_OPLOCK_LEVEL_NONE;
>         cr_req.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION;
>         cr_req.desired_access = SMB2_READ_CONTROL;
>         cr_req.file_attributes = 0;
>         cr_req.share_access = SMB2_FILE_SHARE_READ | SMB2_FILE_SHARE_WRITE;
>         cr_req.create_disposition = SMB2_FILE_OPEN;
>         cr_req.create_options = 0;
>         cr_req.name = path;
> 
>         pdu = smb2_cmd_create_async(smb2, &cr_req, stat_cb_1, stat_data);
>         if (pdu == NULL) {
>                 fprintf(stderr, "Failed to create create command");
>                 free(stat_data);
>                 return -1;
>         }
> 
>         /* QUERY INFO command */
>         memset(&qi_req, 0, sizeof(struct smb2_query_info_request));
>         qi_req.info_type = SMB2_0_INFO_SECURITY;
>         qi_req.output_buffer_length = 65535;
>         qi_req.additional_information =
>                 SMB2_OWNER_SECURITY_INFORMATION |
>                 SMB2_GROUP_SECURITY_INFORMATION |
>                 SMB2_DACL_SECURITY_INFORMATION;
>         memcpy(qi_req.file_id, compound_file_id, SMB2_FD_SIZE);
> 
>         next_pdu = smb2_cmd_query_info_async(smb2, &qi_req,
>                                              stat_cb_2, stat_data);
>         if (next_pdu == NULL) {
>                 fprintf(stderr, "Failed to create query command");
>                 free(stat_data);
>                 smb2_free_pdu(smb2, pdu);
>                 return -1;
>         }
>         smb2_add_compound_pdu(smb2, pdu, next_pdu);
> 
>         /* CLOSE command */
>         memset(&cl_req, 0, sizeof(struct smb2_close_request));
>         cl_req.flags = SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB;
>         memcpy(cl_req.file_id, compound_file_id, SMB2_FD_SIZE);
> 
>         next_pdu = smb2_cmd_close_async(smb2, &cl_req, stat_cb_3, stat_data);
>         if (next_pdu == NULL) {
>                 stat_data->cb(smb2, -1, NULL, stat_data->cb_data);
>                 free(stat_data);
>                 smb2_free_pdu(smb2, pdu);
>                 return -1;
>         }
>         smb2_add_compound_pdu(smb2, pdu, next_pdu);
> 
>         smb2_queue_pdu(smb2, pdu);
> 
> regards
> ronnie sahlberg

This looks nice Ronnie ! Do you want to make it a
project under samba.org somewhere ?

Makes all the libraries available in one place !

Jeremy.



More information about the samba-technical mailing list