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

config: expand tilde for ~/.ceph/$cluster.conf #20774

Merged
merged 1 commit into from Mar 27, 2018

Conversation

rishabh-d-dave
Copy link
Contributor

Fixes: http://tracker.ceph.com/issues/23215
Signed-off-by: Rishabh Dave ridave@redhat.com

@wjwithagen
Copy link
Contributor

I would very much not do this in application code.
~ expansion is most certainly a shell type thing.
So best just leave it there.

The fact that it is somewhere in the CEPH config is IMHO a problem in itself.
If anything needs to be done like that I suggest making it expand $home, like things as $cluster, that keeps things consistant

And even then the way it is now implemented is that EVERY ~ is replaced, even if it is not at the beginning of the file-path. Which is way much more than what is done by any shell expansion.

@rishabh-d-dave
Copy link
Contributor Author

The fact that it is somewhere in the CEPH config is IMHO a problem in itself.
If anything needs to be done like that I suggest making it expand $home, like things as $cluster, that keeps things consistant

Why do you think it is about ceph config?

It is not about tilde somewhere in ceph config. It is with the fact that ~/.ceph/$cluster.conf is checked and processed for '$' properly but never for '~'. As a result, files like ~/.ceph/ceph.conf are never opened by the rados code even if they are meant to be opened [1]. This [2] where the bug is reproduced.

And even then the way it is now implemented is that EVERY ~ is replaced, even if it is not at the beginning of the file-path. Which is way much more than what is done by any shell expansion.

No. My code specifically looks if tilde is at the zeroth index of the given string s. So, not every tilde would be replaced.

[1] https://github.com/ceph/ceph/blob/master/src/common/config.cc#L45
[2] #20598 (comment)

@wjwithagen
Copy link
Contributor

Well my argument is that is should not have been used in this format to begin with, and the PR should be to remove ~/.ceph/$cluster.conf from

./src/common/config.cc:44:static const char *CEPH_CONF_FILE_DEFAULT = "$data_dir/config, /etc/ceph/$cluster.conf, ~/.ceph/$cluster.conf, $cluster.conf"

And if anything like this was required, replace it by $home/.ceph/$cluster.conf.

@@ -248,6 +248,9 @@ int md_config_t::parse_config_files(const char *conf_files,
} else {
cfl.erase(p++); // ignore this item
}
} else if (s.find("~") == 0) {
s.replace(s.find("~"), 1, string(getenv("HOME")));
Copy link
Contributor

Choose a reason for hiding this comment

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

Could replace s.replace(s.find("~"), 1, string(getenv("HOME")));
by s.replace(0, 1, string(getenv("HOME")));

@@ -248,6 +248,9 @@ int md_config_t::parse_config_files(const char *conf_files,
} else {
cfl.erase(p++); // ignore this item
}
} else if (s.find("$home") != string::npos) {
s.replace(0, 5, string(getenv("HOME")));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it be more appropriate to move this part to somewhere in expand_meta()?

Copy link
Contributor

Choose a reason for hiding this comment

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

@rishabh-d-dave
I think that would make sense, it would then be more universially applicable.

@rishabh-d-dave rishabh-d-dave force-pushed the fix-tilde-expansion branch 2 times, most recently from 9a1f7e1 to 697959c Compare March 13, 2018 08:14
Copy link
Member

@liewegas liewegas left a comment

Choose a reason for hiding this comment

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

Works for me (I have no opinion on $home vs ~)

@liewegas
Copy link
Member

retest this please

@rishabh-d-dave
Copy link
Contributor Author

rishabh-d-dave commented Mar 14, 2018

@wjwithagen, @liewegas I don't why make check failed. Locally, it's passing for me -
ceph-make-check-for-PR-20774.txt

@wjwithagen
Copy link
Contributor

@rishabh-d-dave
Looks like ceph-conf fails.
Could be transient, but might have to do with ~ change, which it this case the $home translation does not work out the same as in your work environment.
And that could be that because ~ was non functional before your change.
But now it is, and the $home/ceph.conf does not actually contain what you need in the jenkins test env.

Fixing bug like this, where Jenkins does something different are not easy.
Might want to set to DNM, and submit some debug code, to later remove it once you fixed it.

Copy link
Contributor

@tchaikov tchaikov left a comment

Choose a reason for hiding this comment

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

            raise Error('error executing ceph-conf', e, err)
        if ret == 1:
            # config entry not found
            return None
        elif ret != 0:
>           raise Error('getting variable from configuration failed')
E           Error: Error: getting variable from configuration failed

in run-tox-ceph-disk

@tchaikov
Copy link
Contributor

retest this please.

@rishabh-d-dave
Copy link
Contributor Author

Before ceph-conf runs this time, the chosen ceph conf file would be displayed and it would be checked if it exists. WRT to how Jenkins runs the test, I'm not sure if the debugging code would really help.

@wjwithagen

Might want to set to DNM, and submit some debug code, to later remove it once you fixed it.

What's DNM?

@tchaikov
Copy link
Contributor

@rishabh-d-dave "DNM" stands for "do not merge". @wjwithagen suggested to add this label to your PR so we don't merge it by accident.

@ajarr ajarr added the DNM label Mar 15, 2018
@rishabh-d-dave
Copy link
Contributor Author

retest this please

@rishabh-d-dave
Copy link
Contributor Author

rishabh-d-dave commented Mar 22, 2018

@wjwithagen @tchaikov From the output of the debug code, ~/.ceph/ceph.conf was never chosen from CEPH_CONF_FILE_DEFAULT. IMO, this must mean that the errors are not due to the changes.

Copy link
Member

@liewegas liewegas left a comment

Choose a reason for hiding this comment

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

Please drop the debug commit and rebase. When I test the first commit only locally it looks ok

@@ -1156,6 +1169,8 @@ Option::value_t md_config_t::_expand_meta(
out += stringify(getpid());
} else if (var == "cctid") {
out += stringify((unsigned long long)this);
} else if (var == "home") {
out = string(getenv("HOME"));
Copy link
Member

Choose a reason for hiding this comment

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

Small issue: getenv() can return NULL, and std:;string crashes when passed null. Change to

const char *home = getenv("HOME");
out = home ? std::string(home) : std::string();

or similar

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

And expand "$home" to get the actual path to ceph.conf.

Fixes: http://tracker.ceph.com/issues/23215
Signed-off-by: Rishabh Dave <ridave@redhat.com>
@liewegas liewegas added needs-qa and removed DNM labels Mar 24, 2018
@tchaikov tchaikov merged commit fc86c2b into ceph:master Mar 27, 2018
@rishabh-d-dave rishabh-d-dave deleted the fix-tilde-expansion branch February 19, 2019 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants