Skip to contentSkip to conversation

cifs.upcall: add option to enable debug logs

PATCH Superseded Pierguido Lambri 3 participants 5 messages Jan 29 – Apr 16

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/3 cifs.upcall: add option to enable debug logs

cifs.upcall uses two levels of logs, DEBUG and ERR. However, when using systemd, these logs will always be recorded. When the system does a lot of upcalls, the journal could be filled with debug logs, which may not be useful at that time. Added then a new option '-d' to enable debug logs only when needed. This will set a logmask up to LOG_DEBUG instead of the default of LOG_ERR, thus reducing the amount of logs when no debug is needed.

---
 cifs.upcall.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
cifs.upcall.c +10 -2
index 69e27a3..9c2843d 100644
@@ -1356,7 +1356,7 @@ lowercase_string(char *c)
 
 static void usage(void)
 {
-	fprintf(stderr, "Usage: %s [ -K /path/to/keytab] [-k /path/to/krb5.conf] [-E] [-t] [-v] [-l] [-e nsecs] key_serial\n", prog);
+	fprintf(stderr, "Usage: %s [ -K /path/to/keytab] [-k /path/to/krb5.conf] [-d] [-E] [-t] [-v] [-l] [-e nsecs] key_serial\n", prog);
 }
 
 static const struct option long_options[] = {
@@ -1379,6 +1379,7 @@ int main(const int argc, char *const argv[])
 	size_t datalen;
 	long rc = 1;
 	int c;
+	int mask;
 	bool try_dns = false, legacy_uid = false , env_probe = true;
 	char *buf;
 	char hostbuf[NI_MAXHOST], *host;
@@ -1395,12 +1396,19 @@ int main(const int argc, char *const argv[])
 	hostbuf[0] = '\0';
 
 	openlog(prog, 0, LOG_DAEMON);
+	mask = LOG_UPTO(LOG_ERR);
+	setlogmask(mask);
 
-	while ((c = getopt_long(argc, argv, "cEk:K:ltve:", long_options, NULL)) != -1) {
+	while ((c = getopt_long(argc, argv, "cdEk:K:ltve:", long_options, NULL)) != -1) {
 		switch (c) {
 		case 'c':
 			/* legacy option -- skip it */
 			break;
+		case 'd':
+			/* enable debug logs */
+			mask = LOG_UPTO(LOG_DEBUG);
+			setlogmask(mask);
+			break;
 		case 'E':
 			/* skip probing initiating process env */
 			env_probe = false;
Signature · 1 line
2.52.0
#1 lore raw

PATCH v2 2/3 docs: Enable debug logs

Document a new option '-d' to enable debug logs. By default only error logs are enabled, with this new option debug logs can be enabled when needed.

---
 cifs.upcall.rst.in | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
cifs.upcall.rst.in +4 -1
index 09d0503..73934ef 100644
@@ -11,7 +11,7 @@ Userspace upcall helper for Common Internet File System (CIFS)
 SYNOPSIS
 ********
 
-  cifs.upcall [--trust-dns|-t] [--version|-v] [--legacy-uid|-l]
+  cifs.upcall [--trust-dns|-t] [--version|-v] [--legacy-uid|-l] [-d]
               [--krb5conf=/path/to/krb5.conf|-k /path/to/krb5.conf]
               [--keytab=/path/to/keytab|-K /path/to/keytab] [--expire|-e nsecs] {keyid}
 
@@ -38,6 +38,9 @@ OPTIONS
 -c
   This option is deprecated and is currently ignored.
 
+-d
+  Enable debug logs. By default no debug messages are logged, only errors.
+
 --no-env-probe|-E
   Normally, ``cifs.upcall`` will probe the environment variable space of
   the process that initiated the upcall in order to fetch the value of
Signature · 1 line
2.52.0
#2 lore raw

PATCH v2 3/3 cifs.upcall: Adjust log level

In reply to Pierguido Lambri

Because now only error message are logged, let's switch some messages from DEBUG to ERROR level.
This will help see when an error occurred with cifs.upcall and eventually turn on the debug mode.

---
 cifs.upcall.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
cifs.upcall.c +2 -2
index 9c2843d..9da5289 100644
@@ -1617,7 +1617,7 @@ int main(const int argc, char *const argv[])
 					 __func__);
 		} else {
 			 if (!get_tgt_time(ccache)) {
-				syslog(LOG_DEBUG, "%s: valid TGT is not present in credential cache",
+				syslog(LOG_ERR, "%s: valid TGT is not present in credential cache",
 						__func__);
 				krb5_cc_close(context, ccache);
 				ccache = NULL;
@@ -1720,7 +1720,7 @@ retry_new_hostname:
 	}
 
 	if (rc) {
-		syslog(LOG_DEBUG, "Unable to obtain service ticket");
+		syslog(LOG_ERR, "Unable to obtain service ticket");
 		goto out;
 	}
 
Signature · 1 line
2.52.0
#3 lore raw
In reply to Pierguido Lambri

merged the three patches into cifs-utils for-next

Quoted 61 lines · Pierguido Lambri

cifs.upcall uses two levels of logs, DEBUG and ERR. However, when using systemd, these logs will always be recorded. When the system does a lot of upcalls, the journal could be filled with debug logs, which may not be useful at that time. Added then a new option '-d' to enable debug logs only when needed. This will set a logmask up to LOG_DEBUG instead of the default of LOG_ERR, thus reducing the amount of logs when no debug is needed.

---
 cifs.upcall.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
cifs.upcall.c +10 -3
index 69e27a3..9c2843d 100644
@@ -1356,7 +1356,7 @@ lowercase_string(char *c)
 
 static void usage(void)
 {
-       fprintf(stderr, "Usage: %s [ -K /path/to/keytab] [-k /path/to/krb5.conf] [-E] [-t] [-v] [-l] [-e nsecs] key_serial\n", prog);
+       fprintf(stderr, "Usage: %s [ -K /path/to/keytab] [-k /path/to/krb5.conf] [-d] [-E] [-t] [-v] [-l] [-e nsecs] key_serial\n", prog);
 }
 
 static const struct option long_options[] = {
@@ -1379,6 +1379,7 @@ int main(const int argc, char *const argv[])
        size_t datalen;
        long rc = 1;
        int c;
+       int mask;
        bool try_dns = false, legacy_uid = false , env_probe = true;
        char *buf;
        char hostbuf[NI_MAXHOST], *host;
@@ -1395,12 +1396,19 @@ int main(const int argc, char *const argv[])
        hostbuf[0] = '\0';
 
        openlog(prog, 0, LOG_DAEMON);
+       mask = LOG_UPTO(LOG_ERR);
+       setlogmask(mask);
 
-       while ((c = getopt_long(argc, argv, "cEk:K:ltve:", long_options, NULL)) != -1) {
+       while ((c = getopt_long(argc, argv, "cdEk:K:ltve:", long_options, NULL)) != -1) {
                switch (c) {
                case 'c':
                        /* legacy option -- skip it */
                        break;
+               case 'd':
+                       /* enable debug logs */
+                       mask = LOG_UPTO(LOG_DEBUG);
+                       setlogmask(mask);
+                       break;
                case 'E':
                        /* skip probing initiating process env */
                        env_probe = false;
--

2.52.0

Signature · 3 lines
Thanks,

Steve
#4 lore raw
Quoted 47 lines · Steve French

merged the three patches into cifs-utils for-next

Quoted 43 lines · Pierguido Lambri

cifs.upcall uses two levels of logs, DEBUG and ERR. However, when using systemd, these logs will always be recorded. When the system does a lot of upcalls, the journal could be filled with debug logs, which may not be useful at that time. Added then a new option '-d' to enable debug logs only when needed. This will set a logmask up to LOG_DEBUG instead of the default of LOG_ERR, thus reducing the amount of logs when no debug is needed.

---
 cifs.upcall.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
cifs.upcall.c +4 -1
index 69e27a3..9c2843d 100644
@@ -1356,7 +1356,7 @@ lowercase_string(char *c)
 
 static void usage(void)
 {
-       fprintf(stderr, "Usage: %s [ -K /path/to/keytab] [-k /path/to/krb5.conf] [-E] [-t] [-v] [-l] [-e nsecs] key_serial\n", prog);
+       fprintf(stderr, "Usage: %s [ -K /path/to/keytab] [-k /path/to/krb5.conf] [-d] [-E] [-t] [-v] [-l] [-e nsecs] key_serial\n", prog);
 }
 
 static const struct option long_options[] = {
@@ -1379,6 +1379,7 @@ int main(const int argc, char *const argv[])
        size_t datalen;
        long rc = 1;
        int c;
+       int mask;
        bool try_dns = false, legacy_uid = false , env_probe = true;
        char *buf;
        char hostbuf[NI_MAXHOST], *host;
@@ -1395,12 +1396,19 @@ int main(const int argc, char *const argv[])
        hostbuf[0] = '\0';
 
        openlog(prog, 0, LOG_DAEMON);
+       mask = LOG_UPTO(LOG_ERR);
+       setlogmask(mask);
 
Quoted 11 lines

cifs.upcall.c int main(const int argc, char *const argv[]) · line 1411

Quoted 11 lines
cifs.upcall.c +6 -1
-       while ((c = getopt_long(argc, argv, "cEk:K:ltve:", long_options, NULL)) != -1) {
+       while ((c = getopt_long(argc, argv, "cdEk:K:ltve:", long_options, NULL)) != -1) {
                switch (c) {
                case 'c':
                        /* legacy option -- skip it */
                        break;
+               case 'd':
+                       /* enable debug logs */
+                       mask = LOG_UPTO(LOG_DEBUG);
+                       setlogmask(mask);
+                       break;

I agree that journal can get very verbose when cifs makes many upcalls. Looks like logging behavior is similar across other cifs-utils programs like cifs-idmap.

If we need debug logs from customer devices, asking them to manually modify cifs.spnego.conf with -d could be error-prone.

Should we consider a standardized way to enable debug logging across all cifs-utils components and also with per binary basis to ensure consistent behavior
and reduce misconfig?
One idea could be something like having /etc/cifs-utils/debug file to configure debug level for cifs-utils and also additionally for per binary level. Thoughts.?