Skip to content

Warnings and Errors and Other Things#60986

Closed
adamemerson wants to merge 50 commits intoceph:mainfrom
adamemerson:wip-warnings-errors
Closed

Warnings and Errors and Other Things#60986
adamemerson wants to merge 50 commits intoceph:mainfrom
adamemerson:wip-warnings-errors

Conversation

@adamemerson
Copy link
Contributor

@adamemerson adamemerson commented Dec 6, 2024

A cleanup

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands
  • jenkins retest this please
  • jenkins test classic perf
  • jenkins test crimson perf
  • jenkins test signed
  • jenkins test make check
  • jenkins test make check arm64
  • jenkins test submodules
  • jenkins test dashboard
  • jenkins test dashboard cephadm
  • jenkins test api
  • jenkins test docs
  • jenkins render docs
  • jenkins test ceph-volume all
  • jenkins test ceph-volume tox
  • jenkins test windows
  • jenkins test rook e2e

char tmp[strlen(first)+1];
dashes_to_underscores(first, tmp);
first = tmp;
std::vector<char> tmp(strlen(first) + 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

if this PR isa about memory safety, maybe change to strnlen?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what the limit should be since they're null terminated strings on the command line. ARG_MAX?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(I guess _POSIX_ARG_MAX might be more portable, since ARG_MAX isn't defined everywhere. I could potentially call sysconf, too.)


private:
#if defined(__cpp_lib_atomic_shared_ptr)
std::atomic<std::shared_ptr<neorados::IOContext>> data_io_context;
Copy link
Contributor

Choose a reason for hiding this comment

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

The commit is titled "librbd: Fix atomic shared pointer situation", but there is no description. Can you explain what is being fixed? Given that atomic_*(&data_io_context) usage that was deprecated in C++20 remains, I'm not sure I see the point of this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My understanding is that the atomic_store specialization on shared_ptr per se was deprecated. (https://en.cppreference.com/w/cpp/memory/shared_ptr/atomic), with the recommendation to replace it with atomic<shared_ptr>.

We can use std::atomic_store on any std::atomic<T>* (https://en.cppreference.com/w/cpp/atomic/atomic_store), essentially equivalent to the store member function.

GCC11 doesn't have the atomic<shared_ptr> specialization so we have to keep the regular shared_ptr for now until we can be rid of it, but we can use the new one in new compilers. (And based on the implementation note in CPPreference, the usual implementation of atomic_store<shared_ptr> sounds terrible and we probably want to not use it whenever possible.)

I'll put an explanation in the commit message.

@github-actions
Copy link

github-actions bot commented Jan 9, 2025

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@jmundack jmundack mentioned this pull request Jan 9, 2025
14 tasks
@jmundack
Copy link
Contributor

@adamemerson - thanks for cleaning up all this!

Copy link
Contributor

@chardan chardan left a comment

Choose a reason for hiding this comment

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

Thanks for doing all of this work! I think the changes are really big improvements! Please double-check for situations with vector<T *> that things are getting destroyed in the way you expect, and consider std::string for cases where a character buffer is intended rather than some kind of binary-flavor data. (Alternatively, you can use a unique_ptr<> with a deleter, example included in notes.)

NOTE: please check to be sure they aren't just moving pointers around-- I may not have checked carefully enough (for which I apologize!), if they don't make copies please disregard.

Since we have an obscenely wide supported version spread, we have to
support the deprecated location, too.

Signed-off-by: Adam Emerson <aemerson@redhat.com>
The `lruset` and `not_before_queue` tests require the error category
from `buffer.cc`. Optimization removes any actual use of the category,
so the link error only shows up when compiling `-O0`.

Signed-off-by: Adam Emerson <aemerson@redhat.com>
To fix compile error on jammy

Signed-off-by: Adam Emerson <aemerson@redhat.com>
Otherwise we hit a linker error when compiling with `-O0` due to the
use of `buffer::error_category` not being optimized out.

Signed-off-by: Adam Emerson <aemerson@redhat.com>
libstdc++ uses TBB to implement the execution library if it is
available. If it's not present, we get a serial backend.

Currently, we aren't getting link errors in most cases because the
reference is optimized out, but when compiling with `-O0`, we hit a
missing symbol.

If we use more of the execution library, we'll reference TBB in ways
that don't optimize out.

As such, test if TBB is available. If so, link against it.

Signed-off-by: Adam Emerson <aemerson@redhat.com>
Signed-off-by: Adam Emerson <aemerson@redhat.com>
Signed-off-by: Adam Emerson <aemerson@redhat.com>
Signed-off-by: Adam Emerson <aemerson@redhat.com>
Signed-off-by: Adam Emerson <aemerson@redhat.com>
Signed-off-by: Adam Emerson <aemerson@redhat.com>
Signed-off-by: Adam Emerson <aemerson@redhat.com>
Signed-off-by: Adam Emerson <aemerson@redhat.com>
Signed-off-by: Adam Emerson <aemerson@redhat.com>
Signed-off-by: Adam Emerson <aemerson@redhat.com>
Signed-off-by: Adam Emerson <aemerson@redhat.com>
Signed-off-by: Adam Emerson <aemerson@redhat.com>
Signed-off-by: Adam Emerson <aemerson@redhat.com>
Signed-off-by: Adam Emerson <aemerson@redhat.com>
Signed-off-by: Adam Emerson <aemerson@redhat.com>
Signed-off-by: Adam Emerson <aemerson@redhat.com>
Signed-off-by: Adam Emerson <aemerson@redhat.com>
In the first branch of the if statement `remainingBytes` may be more
than the size of the `uint64_t`.

Signed-off-by: Adam Emerson <aemerson@redhat.com>
Copy link
Contributor

@chardan chardan left a comment

Choose a reason for hiding this comment

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

+1! This is a big improvement, I think! I had a few comments about things you COULD do, but if this is passing Teuthology it's looking good to me, thank you for the hard work on it!

list(APPEND EXTRALIBS gcov)
endif(${ENABLE_COVERAGE})

# libstdc++ uses TBB to implement <execution> if it is available,
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

char buf[len];
hex2str(secret.c_str(), secret.length(), buf, len);
s = buf;
// Since we have to copy the result into the string anyway, we may
Copy link
Contributor

Choose a reason for hiding this comment

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

+1!

s.resize(len);
}
len = hex2str(secret.c_str(), secret.length(), s.data(), len);
s.resize(len);
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider making line 601 always happen? (Then, this and the if-statement can go away.)

#define _CEPH_CLIENT_ID "ceph.client_id"
#endif

static constexpr std::size_t sv_reserve = 1'024;
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for snazzy decimal literal

char secret[seed.length()];
char *psecret = secret;
std::vector<char> secret(seed.length());
char *psecret = secret.data();
Copy link
Contributor

Choose a reason for hiding this comment

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

On line 295 there's a possibility of free() being called on this. Can the psecret pointer go away?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh... So... IF need_free gets set, psecret is re-assigned (line 282) and then free()ed.


std::string key{HTTP_};
key.reserve(name.size() + HTTP_.size());
std::transform(name.cbegin(), name.cend(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this what that dash-to-underscore function we saw earlier does? Maybe replace the implementation with this..? Or make this a Named Function? It's also ok as-written-- +1 map... er... transform().

std::string buf;
buf.reserve(orig.size());

std::transform(orig.begin(), orig.cend(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm. Same thing, but tolower() instead of toupper(). I think this is still an improvement, but it does start my head-scratching!

return string(buf);
std::string buf;
buf.reserve(orig.size());
std::transform(orig.cbegin(), orig.cend(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider also boost::string::to_lower().

mod.reserve(orig.size());
std::transform(orig.cbegin(), orig.cend(),
std::back_inserter(mod),
[](char c) { return char(toupper(underscise(c))); });
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! (Maybe apply to the other similar cases.)

std::string_view src(tok, len);
std::string key;
key.reserve(len);
std::transform(src.cbegin(), src.cend(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, this pattern is definitely common enough that (I know you're probably tired of tinkering with this!) it would be good to see some kind of up/low-er_underscise() to have it in one place (strictly IMO though).

char buf[size];
char tmp_dest[size + 4]; /* so that there's space for the extra '=' characters, and some */
std::vector<char> buf(size);
std::vector<char> tmp_dest(size + 4); /* so that there's space for the extra '=' characters, and some */
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems odd that the dest-ptr would give us a size that we're going to ignore, though..?

}
tmp_dest[ret] = '\0';
memcpy(dest, tmp_dest, size);
memcpy(dest, tmp_dest.data(), size);
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like it's ok if this truncates, then..?

@github-actions
Copy link

github-actions bot commented Feb 5, 2025

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@ronen-fr
Copy link
Contributor

Note: commit 7e3f243 should be backported to Squid, to handle https://tracker.ceph.com/issues/69659

@adamemerson adamemerson marked this pull request as draft April 3, 2025 23:21
@adamemerson
Copy link
Contributor Author

Breaking these out into separate PRs so they can get approved/tested/merged individually

@github-actions
Copy link

github-actions bot commented Jun 3, 2025

This pull request has been automatically marked as stale because it has not had any activity for 60 days. It will be closed if no further activity occurs for another 30 days.
If you are a maintainer or core committer, please follow-up on this pull request to identify what steps should be taken by the author to move this proposed change forward.
If you are the author of this pull request, thank you for your proposed contribution. If you believe this change is still appropriate, please ensure that any feedback has been addressed and ask for a code review.

@github-actions github-actions bot added the stale label Jun 3, 2025
@github-actions
Copy link

github-actions bot commented Jul 3, 2025

This pull request has been automatically closed because there has been no activity for 90 days. Please feel free to reopen this pull request (or open a new one) if the proposed change is still appropriate. Thank you for your contribution!

@github-actions github-actions bot closed this Jul 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants