@@ -85,7 +85,7 @@ const LockType CDentry::versionlock_type(CEPH_LOCK_DVERSION);
8585ostream& operator <<(ostream& out, const CDentry& dn)
8686{
8787 filepath path;
88- dn.make_path (path);
88+ dn.make_trimmed_path (path);
8989
9090 out << " [dentry " << path;
9191
@@ -300,24 +300,74 @@ void CDentry::clear_auth()
300300 }
301301}
302302
303- void CDentry::make_path_string (string& s, bool projected) const
303+ void CDentry::make_path_string (string& s, bool projected,
304+ int path_comp_count) const
304305{
305306 if (dir) {
306- dir->inode ->make_path_string (s, projected);
307+ dir->inode ->make_path_string (s, projected, NULL , path_comp_count );
307308 } else {
308309 s = " ???" ;
309310 }
310311 s += " /" ;
311312 s.append (name.data (), name.length ());
312313}
313314
314- void CDentry::make_path (filepath& fp, bool projected) const
315+ /* path_comp_count = path component count. default value is 10 which implies
316+ * generate entire path.
317+ *
318+ * XXX Generating more than 10 components of a path for printing in logs will
319+ * consume too much time when the path is too long (imagine a path with 2000
320+ * components) since the path would've to be generated indidividually for each
321+ * log entry.
322+ *
323+ * Besides consuming too much time, such long paths in logs are not only not
324+ * useful but also it makes reading logs harder. Therefore, shorten the path
325+ * when used for logging.
326+ */
327+ void CDentry::make_trimmed_path_string (string& s, bool projected,
328+ int path_comp_count) const
315329{
316- ceph_assert (dir);
317- dir->inode ->make_path (fp, projected);
318- fp.push_dentry (get_name ());
330+ make_path_string (s, projected, path_comp_count);
331+ }
332+
333+ /* path_comp_count = path component count. default value is -1 which implies
334+ * generate entire path.
335+ */
336+ void CDentry::make_path (filepath& fp, bool projected,
337+ int path_comp_count) const
338+ {
339+ fp.set_trimmed ();
340+
341+ if (path_comp_count == -1 ) {
342+ ceph_assert (dir);
343+ dir->inode ->make_path (fp, projected, path_comp_count);
344+ fp.push_dentry (get_name ());
345+ } else if (path_comp_count >= 1 ) {
346+ --path_comp_count;
347+
348+ ceph_assert (dir);
349+ dir->inode ->make_path (fp, projected, path_comp_count);
350+ fp.push_dentry (get_name ());
351+ }
319352}
320353
354+ /* path_comp_count = path component count. default value is 10 which implies
355+ * generate entire path.
356+ *
357+ * XXX Generating more than 10 components of a path for printing in logs will
358+ * consume too much time when the path is too long (imagine a path with 2000
359+ * components) since the path would've to be generated indidividually for each
360+ * log entry.
361+ *
362+ * Besides consuming too much time, such long paths in logs are not only not
363+ * useful but also it makes reading logs harder. Therefore, shorten the path
364+ * when used for logging.
365+ */
366+ void CDentry::make_trimmed_path (filepath& fp, bool projected,
367+ int path_comp_count) const
368+ {
369+ make_path (fp, projected, path_comp_count);
370+ }
321371/*
322372 * we only add ourselves to remote_parents when the linkage is
323373 * active (no longer projected). if the passed dnl is projected,
0 commit comments