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

feat(backingimage): support v2 backing image #168

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ChanYiLin
Copy link

@ChanYiLin ChanYiLin commented Nov 28, 2024

ref: longhorn/longhorn#6341

## bdev_lvol_resize

Example request:
{
  "jsonrpc": "2.0",
  "method": "bdev_lvol_resize",
  "id": 1,
  "params": {
    "name": "51638754-ca16-43a7-9f8f-294a0805ab0a",
    "size_in_mib": 2
  }
}
Example response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": true
}
  • Fix nvmecli to use c.GlobalString instead of c.String

ref: longhorn/longhorn 6341

Signed-off-by: Jack Lin <[email protected]>
@ChanYiLin ChanYiLin self-assigned this Nov 28, 2024
Copy link

coderabbitai bot commented Nov 28, 2024

Walkthrough

This pull request introduces several modifications primarily focused on the logical volume resize functionality. The command BdevLvolResizeCmd in app/cmd/basic/bdev_lvol.go has had its flag for size changed from size to size-in-mib, along with updates to its usage documentation. Additionally, the BdevLvolResize method in pkg/spdk/client/basic.go and the BdevLvolResizeRequest type in pkg/spdk/types/lvol.go have been updated to reflect the new naming convention for size parameters. The retrieval of the "host-proc" parameter in the nvmecli package has also been adjusted to ensure consistency in accessing global context.

Changes

File Path Change Summary
app/cmd/basic/bdev_lvol.go Renamed flag from size to size-in-mib in BdevLvolResizeCmd; updated usage string accordingly.
pkg/spdk/client/basic.go Updated BdevLvolResize method parameter from size to sizeInMib.
pkg/spdk/types/lvol.go Changed field name from Size to SizeInMib in BdevLvolResizeRequest.
app/cmd/nvmecli/nvmecli.go Changed retrieval of "host-proc" from c.String("host-proc") to c.GlobalString("host-proc") in several command functions.

Possibly related PRs

  • feat: add API bdev_lvol_rename #157: The changes in this PR involve modifications to the bdev_lvol command set in app/cmd/basic/bdev_lvol.go, which is directly related to the BdevLvolResizeCmd command in the main PR, as both involve logical volume operations within the same file.

Suggested reviewers

  • innobead
  • DamiaSan
  • derekbit

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (2)
app/cmd/nvmecli/nvmecli.go (1)

Line range hint 1-307: Well-structured CLI implementation with clear separation of concerns.

The code demonstrates good architectural patterns:

  • Clear separation between CLI handling and business logic
  • Consistent command structure and error handling
  • Proper use of the urfave/cli package features

Consider adding the following improvements:

  1. Add command-level validation functions to centralize input validation
  2. Consider implementing command aliases for commonly used commands
  3. Add command-level documentation that includes examples
app/cmd/basic/bdev_lvol.go (1)

399-401: Add usage description for size-in-mib flag.

For consistency with other commands and better clarity, add a usage description specifying that the size is in MiB.

 cli.Uint64Flag{
    Name:     "size-in-mib",
+   Usage:    "Specify the new size in MiB",
    Required: true,
 },
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c396ae7 and 15bee7b.

📒 Files selected for processing (4)
  • app/cmd/basic/bdev_lvol.go (2 hunks)
  • app/cmd/nvmecli/nvmecli.go (6 hunks)
  • pkg/spdk/client/basic.go (1 hunks)
  • pkg/spdk/types/lvol.go (1 hunks)
🔇 Additional comments (4)
pkg/spdk/types/lvol.go (1)

133-134: LGTM! Field name change improves clarity.

The change from Size to SizeInMib makes the unit of measurement explicit and maintains consistency with other structs like BdevLvolCreateRequest.

app/cmd/nvmecli/nvmecli.go (1)

108-108: LGTM! Consistent access to global flag.

The changes correctly update the retrieval of the "host-proc" parameter from c.String to c.GlobalString. This is the proper way to access flags defined at the root command level, ensuring consistent behavior across all subcommands.

Let's verify that the "host-proc" flag is only defined at the root level and not redefined in subcommands:

Also applies to: 134-134, 170-170, 219-219, 260-260, 292-292

✅ Verification successful

Let me analyze the output and generate another verification script to check if the "host-proc" flag is defined in any subcommands of nvmecli:


From the previous output, we can see that the "host-proc" flag is defined only once in nvmecli.go at the root level. Let me verify one more aspect - checking if it's used consistently with GlobalString across all usages:


LGTM! The host-proc flag is correctly defined and used.

The verification confirms that:

  1. The "host-proc" flag is defined once at the root level
  2. It's consistently accessed using c.GlobalString("host-proc") across all functions
  3. All seven functions (discover, connect, disconnect, get, start, stop, and flush) use the correct method to access this global flag
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any duplicate definitions of the host-proc flag
# Expected: Only one definition at the root level

# Search for host-proc flag definitions
ast-grep --pattern 'cli.StringFlag{
  Name: "host-proc",
  $$$
}'

Length of output: 27847


Script:

#!/bin/bash
# Search for any subcommand definitions in nvmecli.go that might redefine the host-proc flag
ast-grep --pattern 'cli.Command{
  $$$
  Flags: []cli.Flag{
    $$$
    cli.StringFlag{
      Name: "host-proc",
      $$$
    },
    $$$
  },
  $$$
}'

Length of output: 153


Script:

#!/bin/bash
# Search for any usage of host-proc in nvmecli.go
rg "host-proc" app/cmd/nvmecli/nvmecli.go -B 1 -A 1

Length of output: 1118

app/cmd/basic/bdev_lvol.go (1)

403-403: LGTM!

The usage string has been correctly updated to reflect the new flag name.

pkg/spdk/client/basic.go (1)

417-419: LGTM! Verify callers of this method

The parameter rename from size to sizeInMib improves clarity about the unit of measurement. The implementation correctly uses the renamed field.

Let's verify all callers of this method have been updated:

✅ Verification successful

All callers have been updated correctly to use size-in-mib

The verification shows that:

  • The BdevLvolResize method is called only once in app/cmd/basic/bdev_lvol.go
  • The caller correctly uses size-in-mib parameter from CLI flags
  • No other callers or size-related assignments were found
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all callers of BdevLvolResize to ensure they're using the correct parameter name
# Test: Search for function calls. Expect: All callers use sizeInMib parameter

# Search for direct function calls
rg -U "BdevLvolResize.*\(" -A 2

# Search for variable assignments that will be used in the function call
rg "(?i)size.*:=.*(?i)mib"

Length of output: 909

Comment on lines +133 to +134
Name string `json:"name"`
SizeInMib uint64 `json:"size_in_mib"`
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

API compatibility issue confirmed - action required

The codebase search reveals that the JSON field rename from "size" to "size_in_mib" will cause compatibility issues:

  • The BdevLvolGetFragmapRequest struct in pkg/spdk/types/lvol.go still uses json:"size" for its Size field
  • The CLI commands in app/cmd/basic/bdev_lvol.go use size parameters in different contexts (both MiB and bytes)
  • The client documentation in pkg/spdk/client/basic.go references the "size" field in the API documentation

This change requires coordinated updates across these locations to maintain consistency and avoid breaking API compatibility.

🔗 Analysis chain

Verify API compatibility for JSON field rename.

The JSON field has been renamed from "size" to "size_in_mib". Please ensure this change is compatible with existing API consumers or that appropriate migration steps are in place.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any direct usage of the old JSON field name
rg -l '"size"' | while read -r file; do
  if [[ "$file" =~ \.json$ ]] || [[ "$file" =~ \.ya?ml$ ]] || [[ "$file" =~ _test\.(go|py|js)$ ]]; then
    echo "=== $file ==="
    rg -A 2 -B 2 '"size"' "$file"
  fi
done

# Search for any struct field references
ast-grep --pattern 'Size uint64' 

Length of output: 1218


Script:

#!/bin/bash
# Let's check the specific files that might be using the JSON field
rg -A 5 -B 5 '"size"' app/cmd/basic/bdev_lvol.go pkg/spdk/types/lvol.go pkg/spdk/client/basic.go

# Also check for any test files that might be using this field
fd -e test.go -x rg -l '"size"' {}

# Look for any JSON struct tags with 'size'
rg 'json:"size"' 

# Check the git history for this specific file to see when this change was made
git log -p pkg/spdk/types/lvol.go | rg -A 5 -B 5 'size.*json'

Length of output: 4102

@@ -420,7 +420,7 @@ func bdevLvolResize(c *cli.Context) error {
name = c.String("uuid")
}

resized, err := spdkCli.BdevLvolResize(name, c.Uint64("size"))
resized, err := spdkCli.BdevLvolResize(name, c.Uint64("size-in-mib"))
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Size parameter naming is inconsistent across lvol operations

The verification revealed inconsistencies in size parameter naming:

  • BdevLvolCreate uses size parameter and flag
  • BdevLvolResize uses size-in-mib flag and sizeInMib parameter
  • BdevLvolGetFragmap uses size parameter (but represents bytes)

The usage descriptions also show inconsistency:

  • Create: "Specify bdev lvol size in MiB"
  • Resize: No usage description for size-in-mib flag
  • GetFragmap: "Size in bytes of the specific segment"
🔗 Analysis chain

LGTM! Verify consistent parameter naming across the codebase.

The client call has been correctly updated to use the new parameter name.

Let's verify that all size-related parameters in lvol operations consistently use the MiB suffix:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistency in size parameter naming across the codebase
# Expected results: All size parameters in lvol operations should use MiB suffix

# Check for size parameters in function signatures and struct fields
ast-grep --pattern 'func $$$BdevLvol$$$($$$ size $$$)'

# Check for size-related CLI flags
rg --type go "cli\.(Uint64|Int64|Float64)Flag.*Name.*size" -A 2

Length of output: 122


Script:

#!/bin/bash
# Let's try a more comprehensive search for size-related parameters in lvol operations

# Search for lvol-related function calls with size parameters
rg --type go "BdevLvol.*size" -B 2 -A 2

# Search for CLI flags related to size in lvol commands
rg --type go "Name:\s+\"size" -B 2 -A 2

# Search for struct fields or parameters containing both lvol and size
ast-grep --pattern 'type $_ struct {
  $$$
  size $$$
  $$$
}'

# Look for specific lvol resize calls
rg --type go "BdevLvolResize.*size" -B 2 -A 2

Length of output: 7824

Comment on lines +415 to +416
// "sizeInMib": Required. Desired size of the logical volume in bytes.
func (c *Client) BdevLvolResize(name string, sizeInMib uint64) (resized bool, err error) {
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix documentation inconsistency

The documentation states the size is "in bytes" but the parameter name suggests it's in MiB. Please update the documentation to be consistent with the parameter name.

Apply this diff to fix the documentation:

-//	"sizeInMib": Required. Desired size of the logical volume in bytes.
+//	"sizeInMib": Required. Desired size of the logical volume in mebibytes (MiB).
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// "sizeInMib": Required. Desired size of the logical volume in bytes.
func (c *Client) BdevLvolResize(name string, sizeInMib uint64) (resized bool, err error) {
// "sizeInMib": Required. Desired size of the logical volume in mebibytes (MiB).
func (c *Client) BdevLvolResize(name string, sizeInMib uint64) (resized bool, err error) {

Copy link

codecov bot commented Nov 28, 2024

Codecov Report

Attention: Patch coverage is 0% with 12 lines in your changes missing coverage. Please review.

Project coverage is 22.95%. Comparing base (c396ae7) to head (15bee7b).

Files with missing lines Patch % Lines
app/cmd/nvmecli/nvmecli.go 0.00% 6 Missing ⚠️
app/cmd/basic/bdev_lvol.go 0.00% 3 Missing ⚠️
pkg/spdk/client/basic.go 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #168      +/-   ##
==========================================
+ Coverage   22.89%   22.95%   +0.06%     
==========================================
  Files          34       34              
  Lines        4813     4813              
==========================================
+ Hits         1102     1105       +3     
+ Misses       3537     3535       -2     
+ Partials      174      173       -1     
Flag Coverage Δ
unittests 22.95% <0.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant