Skip to content

Conversation

@jperon
Copy link
Collaborator

@jperon jperon commented Jul 24, 2025

Fixes #307

@jperon jperon requested review from Copilot and lneto July 24, 2025 16:00
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR replaces the synchronous compression implementation with an asynchronous one using the Linux kernel's acompress API. The change introduces a new low-level crypto.acompress module that provides asynchronous compression operations, while maintaining backward compatibility through a high-level crypto.comp Lua module that wraps the async operations to provide a synchronous interface.

Key changes:

  • Replaces synchronous luacrypto_comp.c with asynchronous luacrypto_acompress.c
  • Adds high-level Lua wrapper crypto/comp.lua to maintain synchronous API compatibility
  • Updates build configuration to use the new acompress module

Reviewed Changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
lib/luacrypto_comp.c Removed - old synchronous compression implementation
lib/luacrypto_acompress.c Added - new asynchronous compression implementation using kernel acompress API
lib/crypto/comp.lua Added - high-level Lua wrapper providing synchronous interface over async operations
tests/crypto/comp.lua Minor error message improvement for clarity
config.ld Updated documentation config to reference new files
Makefile Updated build config to use acompress module
Kbuild Updated kernel build config to use acompress module

@lneto lneto requested a review from sheharyaar July 24, 2025 16:04
@jperon jperon mentioned this pull request Aug 4, 2025
@jperon jperon force-pushed the jperon_crypto_acompress branch from 723e663 to 1df9379 Compare August 6, 2025 14:33
@jperon jperon force-pushed the jperon_crypto_acompress branch from 9a9b7c6 to c0e8987 Compare November 21, 2025 00:34
@jperon jperon force-pushed the jperon_crypto_acompress branch from c0e8987 to 59c56ec Compare November 21, 2025 06:58
static const lunatik_class_t luacrypto_acompress_classes[] = {
luacrypto_acompress_class,
luacrypto_acompress_req_class,
{NULL}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{NULL}
NULL

shouldn't be just NULL, here? the array element is a pointer, not a struct, right?

Comment on lines +184 to +196
/* Table to hold all references */
lua_newtable(L);

lua_pushvalue(L, 4);
lua_setfield(L, -2, "cb");

lua_pushvalue(L, 2);
lua_setfield(L, -2, "buf");

lua_pushvalue(L, 1);
lua_setfield(L, -2, "self");

obj->refs = luaL_ref(L, LUA_REGISTRYINDEX);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think moving this to an auxiliary function, also renaming ref to request (or another name for this table), would make it more readable.. btw, can't we use the object pointer to register this table instead of using a new ref on Lua registry? I would also move the call to this aux function to the macro bellow as it accesses argument indexes directly.. we are trying to reference the argument numbers on the lua_CFunction itself or passing the index to auxiliary functions to make easier to understand the context of the stack

Comment on lines -262 to +309
#define LUNATIK_NEWLIB(libname, funcs, class, namespaces) \
int luaopen_##libname(lua_State *L); \
int luaopen_##libname(lua_State *L) \
{ \
const lunatik_class_t *cls = class; /* avoid -Waddress */ \
const lunatik_namespace_t *nss = namespaces; /* avoid -Waddress */ \
luaL_newlib(L, funcs); \
if (cls) { \
lunatik_checkclass(L, cls); \
lunatik_newclass(L, cls); \
} \
if (nss) \
lunatik_newnamespaces(L, nss); \
return 1; \
} \
static inline void lunatik_register_class(lua_State *L, const lunatik_class_t *class)
{
if (class) {
lunatik_checkclass(L, class);
lunatik_newclass(L, class);
}
}

static inline void lunatik_register_classes(lua_State *L, const lunatik_class_t *classes)
{
if (classes)
lunatik_newclasses(L, classes);
}

static inline void lunatik_register_namespaces(lua_State *L, const lunatik_namespace_t *namespaces)
{
if (namespaces)
lunatik_newnamespaces(L, namespaces);
}

#define LUNATIK_NEWLIB(libname, funcs, class, namespaces) \
int luaopen_##libname(lua_State *L); \
int luaopen_##libname(lua_State *L) \
{ \
luaL_newlib(L, funcs); \
lunatik_register_class(L, class); \
lunatik_register_namespaces(L, namespaces); \
return 1; \
} \
EXPORT_SYMBOL_GPL(luaopen_##libname)

#define LUNATIK_NEWLIB_MULTICLASS(libname, funcs, classes, namespaces) \
int luaopen_##libname(lua_State *L); \
int luaopen_##libname(lua_State *L) \
{ \
luaL_newlib(L, funcs); \
lunatik_register_classes(L, classes); \
lunatik_register_namespaces(L, namespaces); \
return 1; \
} \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, I know that I advised otherwise.. but now that we can see it implemented, I think it would be simpler to have just one API and to just add the class array to LUANATIK_NEWLIB.. I can help to update the other modules if needed.. it will be more alike the flags case.. we also need to keep in mind that we will need to update the README

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also separate this API change in another commit.. before the acompress one

local completion = require("completion")

--- @type COMPRESS
local COMPRESS = {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we are using this pattern (with all caps) elsewhere.. it looked a bit odd to me.. but no strong feelings.. just a note..

Comment on lines +6 to +10
local status, comp = pcall(require, "crypto.comp")
if not status then
print("crypto.comp not available, skipping tests")
return
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of doing this, we can register an empty library in this case.. we already do it on luaxdp if I'm not mistaken..

Comment on lines +59 to +60
u8 *outbuf;
size_t outbuf_len;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a very repetitive pattern, we use it on luadata (perhaps on other modules as well).. wondering if it wouldn't worth to have a lunatik_buffer_t or similar..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Build failing in latest release

3 participants