| 176 | |
| 177 | |
| 178 | int JournalFilter::parse_args( |
| 179 | std::vector<const char*> &argv, |
| 180 | std::vector<const char*>::iterator &arg) |
| 181 | { |
| 182 | while(arg != argv.end()) { |
| 183 | std::string arg_str; |
| 184 | if (ceph_argparse_witharg(argv, arg, &arg_str, "--range", (char*)NULL)) { |
| 185 | size_t sep_loc = arg_str.find(JournalFilter::range_separator); |
| 186 | if (sep_loc == std::string::npos || arg_str.size() <= JournalFilter::range_separator.size()) { |
| 187 | derr << "Invalid range '" << arg_str << "'" << dendl; |
| 188 | return -EINVAL; |
| 189 | } |
| 190 | |
| 191 | // We have a lower bound |
| 192 | if (sep_loc > 0) { |
| 193 | std::string range_start_str = arg_str.substr(0, sep_loc); |
| 194 | std::string parse_err; |
| 195 | range_start = strict_strtoll(range_start_str.c_str(), 0, &parse_err); |
| 196 | if (!parse_err.empty()) { |
| 197 | derr << "Invalid lower bound '" << range_start_str << "': " << parse_err << dendl; |
| 198 | return -EINVAL; |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | if (sep_loc < arg_str.size() - JournalFilter::range_separator.size()) { |
| 203 | std::string range_end_str = arg_str.substr(sep_loc + range_separator.size()); |
| 204 | std::string parse_err; |
| 205 | range_end = strict_strtoll(range_end_str.c_str(), 0, &parse_err); |
| 206 | if (!parse_err.empty()) { |
| 207 | derr << "Invalid upper bound '" << range_end_str << "': " << parse_err << dendl; |
| 208 | return -EINVAL; |
| 209 | } |
| 210 | } |
| 211 | } else if (ceph_argparse_witharg(argv, arg, &arg_str, "--path", (char*)NULL)) { |
| 212 | if (!type.compare("purge_queue")) { |
| 213 | derr << "Invalid filter arguments: purge_queue doesn't take \"--path\"." << dendl; |
| 214 | return -EINVAL; |
| 215 | } |
| 216 | dout(4) << "Filtering by path '" << arg_str << "'" << dendl; |
| 217 | path_expr = arg_str; |
| 218 | } else if (ceph_argparse_witharg(argv, arg, &arg_str, "--inode", (char*)NULL)) { |
| 219 | dout(4) << "Filtering by inode '" << arg_str << "'" << dendl; |
| 220 | std::string parse_err; |
| 221 | inode = strict_strtoll(arg_str.c_str(), 0, &parse_err); |
| 222 | if (!parse_err.empty()) { |
| 223 | derr << "Invalid inode '" << arg_str << "': " << parse_err << dendl; |
| 224 | return -EINVAL; |
| 225 | } |
| 226 | } else if (ceph_argparse_witharg(argv, arg, &arg_str, "--type", (char*)NULL)) { |
| 227 | try { |
| 228 | if (!type.compare("mdlog")) { |
| 229 | event_type = LogEvent::str_to_type(arg_str); |
| 230 | } else if (!type.compare("purge_queue")) { |
| 231 | purge_action = PurgeItem::str_to_type(arg_str); |
| 232 | } |
| 233 | } catch (const std::out_of_range&) { |
| 234 | derr << "Invalid event type '" << arg_str << "'" << dendl; |
| 235 | return -EINVAL; |