Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mount cli integration in C #4851

Merged

Conversation

flo91
Copy link
Collaborator

@flo91 flo91 commented Feb 28, 2023

Implements code for listing mountpoints and mounting new files (includes plugin-resolution and -handling for mounting) in C.
Most of the C++-based code is now implemented in C, but there is still some work left, including testing, and refactoring.

I'll write a posting in this PR and add the label needs review as soon as

  • I've successfully finished and
  • refactored the implementation,
  • tested some use cases and
  • reviewing seems feasible.

Thank you!

Basics

  • Short descriptions of your changes are in the release notes
    (added as entry in doc/news/_preparation_next_release.md which
    contains _(my name)_)
    Please always add something to the release notes.
  • Details of what you changed are in commit messages
    (first line should have module: short statement syntax)
  • References to issues, e.g. close #X, are in the commit messages.
  • The buildservers are happy. If not, fix in this order:
    • add a line in doc/news/_preparation_next_release.md
    • reformat the code with scripts/dev/reformat-all
    • make all unit tests pass
    • fix all memleaks
  • The PR is rebased with current master.

Checklist

  • I added unit tests for my code
  • I fully described what my PR does in the documentation
    (not in the PR description)
  • I fixed all affected documentation (see Documentation Guidelines)
  • I fixed all affected decisions (see Decision Process)
  • I added code comments, logging, and assertions as appropriate (see Coding Guidelines)
  • I updated all meta data (e.g. README.md of plugins and METADATA.ini)
  • I mentioned every code not directly written by me in reuse syntax

Review

Labels

  • Add the "work in progress" label if you do not want the PR to be reviewed yet.
  • Add the "ready to merge" label if the basics are fulfilled and no further pushes are planned by you.

early stage, lots of open TODOs, work in progress
from the new kdb command (work in progress!)
based on parts of the branch "kdb_cli_rewrite" from @hannes99
and add new `kdb mountpoint list` command
re-implement C++-based code for mounting in C
and include elektra-meta as target link lib for src/libs/elektra
needed for handling of plugins during mounting
only draft code, still needs: doc, tests, refactoring
add code for checking conflicts of plugins
for KeySets for infos and symbols (allocation)
@flo91 flo91 self-assigned this Feb 28, 2023
@flo91 flo91 mentioned this pull request Feb 28, 2023
23 tasks
Copy link
Member

@kodebach kodebach left a comment

Choose a reason for hiding this comment

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

I know this isn't done yet, but I had a quick look anyway.

It seems this is basically a 1:1 translation of the C++ code. That's a good start, but there are some things that need to be done differently now that we have backend plugins. I also noticed a few things that could be simplified.

}

/* STEP 2: Check for wrong namespace (proc) */
if (keyGetNamespace (mountPoint) == KEY_NS_PROC)
Copy link
Member

Choose a reason for hiding this comment

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

Mounting into proc:/ is in theory allowed by libelektra-kdb.


/* STEP 3: Check for name match */
const char * mpName = keyName (mountPoint);
if (keyGetNameSize (mountPoint) == 2 && *mpName == '/')
Copy link
Member

Choose a reason for hiding this comment

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

Seems rather complicated... Why not just do a cascading lookup and report the found key in the error?

Key * found = ksLookupByName (alreadyUsedMountpoints, mpName, 0);
if (found != NULL) {
    fprintf (stderr, "Mountpoint '%s' not possible, because mountpoint '%s' already exists.\n", mpName, keyName (found));
}

This should work for all cases of mpName

ksDel (alreadyUsedMountpoints);
ksDel (backendInfos);

/* TODO: STEP 4: Check if mounted below system:/elektra */
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/* TODO: STEP 4: Check if mounted below system:/elektra */
/* TODO: STEP 4: Check if mounted below /elektra in any namespace */

Comment on lines +406 to +413
/* Remove namespace */
for (int i = 0; i < keyGetNameSize (elektraCheck); ++i)
{
if (*(mpName + i) == ':')
{
keySetName (elektraCheck, mpName + i + 1);
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Pretty sure the keyIsBelow* functions handle cascading keys too. Otherwise, please use:

Suggested change
/* Remove namespace */
for (int i = 0; i < keyGetNameSize (elektraCheck); ++i)
{
if (*(mpName + i) == ':')
{
keySetName (elektraCheck, mpName + i + 1);
}
}
/* Remove namespace */
keySetNamespace (elektraCheck, KEY_NS_CASCADING);

size_t lenLookup = keyGetNameSize (cur); /* includes \0 */
if (lenLookup > 1)
{
lenLookup += strlen ("/definition/path");
Copy link
Member

Choose a reason for hiding this comment

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

That key is specific to the backend plugin. We need a more general solution...

*
* @return true if the provided str is a valid plugin-name, false otherwise
*/
bool validatePluginName (const char * str)
Copy link
Member

Choose a reason for hiding this comment

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

AFAIK the name of plugins isn't actually validated anywhere else. The mount code should accept anything that is allowed by libelektra-kdb and elektraPlugin*.

elektraKeyToBoolean (tmp, &optForce);
if ((tmp = GET_OPTION_KEY (options, "quiet")))
elektraKeyToBoolean (tmp, &optQuiet);
if ((tmp = GET_OPTION_KEY (options, "interactive")))
Copy link
Member

Choose a reason for hiding this comment

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

AFAIK we planned to remove the interactive mode, since nobody is using it anyway

if (!optQuiet && *argPath == '/' && keyMpNs != KEY_NS_SYSTEM && keyMpNs != KEY_NS_SPEC && keyMpNs != KEY_NS_CASCADING)
{
printf("Note that absolute paths are still relative to their namespace (see `kdb plugin-info resolver`).\n");
printf("Only system+spec mountpoints are actually absolute.\n");
Copy link
Member

Choose a reason for hiding this comment

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

That still depends on the backend plugin and for backend on resolver plugin. It's just that the default resolver does it this way

printf("Note that absolute paths are still relative to their namespace (see `kdb plugin-info resolver`).\n");
printf("Only system+spec mountpoints are actually absolute.\n");
printf("Use `kdb file %s` to determine where the file(s) are.\n", argMountpoint);
printf("Use `-q` or use `kdb set %s/quiet 1` to suppress infos.\n", CLI_BASE_KEY);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
printf("Use `-q` or use `kdb set %s/quiet 1` to suppress infos.\n", CLI_BASE_KEY);
printf("Use `-q` or use `kdb set %s/quiet 1` to suppress all infos like this.\n", CLI_BASE_KEY);

@flo91
Copy link
Collaborator Author

flo91 commented Mar 6, 2023

As this PR gets merged into ElektraInitiative:mount_cli_integration and not into master,
I'll merge the current state of this PR as requested by @hannes99.
So he can rebase his branch with current master and has the current state of the mount-implementation.

After the rebasing is done, I'll open a new PR with the changes since this PR.

@flo91 flo91 marked this pull request as ready for review March 6, 2023 16:49
@flo91 flo91 merged commit 4fa9ca8 into ElektraInitiative:mount_cli_integration Mar 6, 2023
@flo91 flo91 mentioned this pull request Mar 9, 2023
19 tasks
@flo91 flo91 changed the title WIP: Mount cli integration in C Mount cli integration in C Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants