Skip to content

Commit

Permalink
tipc: remove print_buf and deprecated log buffer code
Browse files Browse the repository at this point in the history
The internal log buffer handling functions can now safely be
removed since there is no code using it anymore.  Requests to
interact with the internal tipc log buffer over netlink (in
config.c) will report 'obsolete command'.

This represents the final removal of any references to a
struct print_buf, and the removal of the struct itself.
We also get rid of a TIPC specific Kconfig in the process.

Finally, log.h is removed since it is not needed anymore.

Signed-off-by: Erik Hugne <[email protected]>
Signed-off-by: Jon Maloy <[email protected]>
Signed-off-by: Paul Gortmaker <[email protected]>
  • Loading branch information
Erik Hugne authored and Paul Gortmaker committed Jul 13, 2012
1 parent dc1aed3 commit 869dd46
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 335 deletions.
4 changes: 2 additions & 2 deletions include/linux/tipc_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@
#define TIPC_CMD_SET_LINK_TOL 0x4107 /* tx link_config, rx none */
#define TIPC_CMD_SET_LINK_PRI 0x4108 /* tx link_config, rx none */
#define TIPC_CMD_SET_LINK_WINDOW 0x4109 /* tx link_config, rx none */
#define TIPC_CMD_SET_LOG_SIZE 0x410A /* tx unsigned, rx none */
#define TIPC_CMD_DUMP_LOG 0x410B /* tx none, rx ultra_string */
#define TIPC_CMD_SET_LOG_SIZE 0x410A /* obsoleted */
#define TIPC_CMD_DUMP_LOG 0x410B /* obsoleted */
#define TIPC_CMD_RESET_LINK_STATS 0x410C /* tx link_name, rx none */

/*
Expand Down
13 changes: 0 additions & 13 deletions net/tipc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,4 @@ config TIPC_PORTS
Setting this to a smaller value saves some memory,
setting it to higher allows for more ports.

config TIPC_LOG
int "Size of log buffer"
depends on TIPC_ADVANCED
range 0 32768
default "0"
help
Size (in bytes) of TIPC's internal log buffer, which records the
occurrence of significant events. Can range from 0 to 32768 bytes;
default is 0.

There is no need to enable the log buffer unless the node will be
managed remotely via TIPC.

endif # TIPC
8 changes: 2 additions & 6 deletions net/tipc/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,6 @@ struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area
case TIPC_CMD_SHOW_PORTS:
rep_tlv_buf = tipc_port_get_ports();
break;
case TIPC_CMD_SET_LOG_SIZE:
rep_tlv_buf = tipc_log_resize_cmd(req_tlv_area, req_tlv_space);
break;
case TIPC_CMD_DUMP_LOG:
rep_tlv_buf = tipc_log_dump();
break;
case TIPC_CMD_SHOW_STATS:
rep_tlv_buf = tipc_show_stats();
break;
Expand Down Expand Up @@ -399,6 +393,8 @@ struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area
case TIPC_CMD_GET_MAX_CLUSTERS:
case TIPC_CMD_SET_MAX_NODES:
case TIPC_CMD_GET_MAX_NODES:
case TIPC_CMD_SET_LOG_SIZE:
case TIPC_CMD_DUMP_LOG:
rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
" (obsolete command)");
break;
Expand Down
7 changes: 0 additions & 7 deletions net/tipc/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@
#define CONFIG_TIPC_PORTS 8191
#endif

#ifndef CONFIG_TIPC_LOG
#define CONFIG_TIPC_LOG 0
#endif

/* global variables used by multiple sub-systems within TIPC */
int tipc_random;
Expand Down Expand Up @@ -124,7 +121,6 @@ static void tipc_core_stop(void)
tipc_nametbl_stop();
tipc_ref_table_stop();
tipc_socket_stop();
tipc_log_resize(0);
}

/**
Expand Down Expand Up @@ -160,9 +156,6 @@ static int __init tipc_init(void)
{
int res;

if (tipc_log_resize(CONFIG_TIPC_LOG) != 0)
pr_warn("Unable to create log buffer\n");

pr_info("Activated (version " TIPC_MOD_VER ")\n");

tipc_own_addr = 0;
Expand Down
27 changes: 0 additions & 27 deletions net/tipc/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,36 +63,9 @@
#define ULTRA_STRING_MAX_LEN 32768

struct tipc_msg; /* msg.h */
struct print_buf; /* log.h */

/*
* TIPC system monitoring code
*/

/*
* TIPC's print buffer subsystem supports the following print buffers:
*
* TIPC_NULL : null buffer (i.e. print nowhere)
* TIPC_CONS : system console
* TIPC_LOG : TIPC log buffer
* &buf : user-defined buffer (struct print_buf *)
*
* Note: TIPC_LOG is configured to echo its output to the system console;
* user-defined buffers can be configured to do the same thing.
*/
extern struct print_buf *const TIPC_NULL;
extern struct print_buf *const TIPC_CONS;
extern struct print_buf *const TIPC_LOG;

int tipc_snprintf(char *buf, int len, const char *fmt, ...);

/*
* TIPC_OUTPUT is the destination print buffer for system messages.
*/
#ifndef TIPC_OUTPUT
#define TIPC_OUTPUT TIPC_LOG
#endif

/*
* TIPC-specific error codes
*/
Expand Down
1 change: 0 additions & 1 deletion net/tipc/link.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#ifndef _TIPC_LINK_H
#define _TIPC_LINK_H

#include "log.h"
#include "msg.h"
#include "node.h"

Expand Down
213 changes: 0 additions & 213 deletions net/tipc/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,138 +36,6 @@

#include "core.h"
#include "config.h"
#include "log.h"

/*
* TIPC pre-defines the following print buffers:
*
* TIPC_NULL : null buffer (i.e. print nowhere)
* TIPC_CONS : system console
* TIPC_LOG : TIPC log buffer
*
* Additional user-defined print buffers are also permitted.
*/
static struct print_buf null_buf = { NULL, 0, NULL, 0 };
struct print_buf *const TIPC_NULL = &null_buf;

static struct print_buf cons_buf = { NULL, 0, NULL, 1 };
struct print_buf *const TIPC_CONS = &cons_buf;

static struct print_buf log_buf = { NULL, 0, NULL, 1 };
struct print_buf *const TIPC_LOG = &log_buf;

/*
* Locking policy when using print buffers.
*
* 1) tipc_printf() uses 'print_lock' to protect against concurrent access to
* 'print_string' when writing to a print buffer. This also protects against
* concurrent writes to the print buffer being written to.
*
* 2) tipc_log_XXX() leverages the aforementioned use of 'print_lock' to
* protect against all types of concurrent operations on their associated
* print buffer (not just write operations).
*
* Note: All routines of the form tipc_printbuf_XXX() are lock-free, and rely
* on the caller to prevent simultaneous use of the print buffer(s) being
* manipulated.
*/
static DEFINE_SPINLOCK(print_lock);

static void tipc_printbuf_move(struct print_buf *pb_to,
struct print_buf *pb_from);

/**
* tipc_printbuf_init - initialize print buffer to empty
* @pb: pointer to print buffer structure
* @raw: pointer to character array used by print buffer
* @size: size of character array
*
* Note: If the character array is too small (or absent), the print buffer
* becomes a null device that discards anything written to it.
*/
void tipc_printbuf_init(struct print_buf *pb, char *raw, u32 size)
{
pb->buf = raw;
pb->crs = raw;
pb->size = size;
pb->echo = 0;

if (size < TIPC_PB_MIN_SIZE) {
pb->buf = NULL;
} else if (raw) {
pb->buf[0] = 0;
pb->buf[size - 1] = ~0;
}
}

/**
* tipc_printbuf_reset - reinitialize print buffer to empty state
* @pb: pointer to print buffer structure
*/
static void tipc_printbuf_reset(struct print_buf *pb)
{
if (pb->buf) {
pb->crs = pb->buf;
pb->buf[0] = 0;
pb->buf[pb->size - 1] = ~0;
}
}

/**
* tipc_printbuf_empty - test if print buffer is in empty state
* @pb: pointer to print buffer structure
*
* Returns non-zero if print buffer is empty.
*/
static int tipc_printbuf_empty(struct print_buf *pb)
{
return !pb->buf || (pb->crs == pb->buf);
}

/**
* tipc_printbuf_move - move print buffer contents to another print buffer
* @pb_to: pointer to destination print buffer structure
* @pb_from: pointer to source print buffer structure
*
* Current contents of destination print buffer (if any) are discarded.
* Source print buffer becomes empty if a successful move occurs.
*/
static void tipc_printbuf_move(struct print_buf *pb_to,
struct print_buf *pb_from)
{
int len;

/* Handle the cases where contents can't be moved */
if (!pb_to->buf)
return;

if (!pb_from->buf) {
tipc_printbuf_reset(pb_to);
return;
}

if (pb_to->size < pb_from->size) {
strcpy(pb_to->buf, "*** PRINT BUFFER MOVE ERROR ***");
pb_to->buf[pb_to->size - 1] = ~0;
pb_to->crs = strchr(pb_to->buf, 0);
return;
}

/* Copy data from char after cursor to end (if used) */
len = pb_from->buf + pb_from->size - pb_from->crs - 2;
if ((pb_from->buf[pb_from->size - 1] == 0) && (len > 0)) {
strcpy(pb_to->buf, pb_from->crs + 1);
pb_to->crs = pb_to->buf + len;
} else
pb_to->crs = pb_to->buf;

/* Copy data from start to cursor (always) */
len = pb_from->crs - pb_from->buf;
strcpy(pb_to->crs, pb_from->buf);
pb_to->crs += len;

tipc_printbuf_reset(pb_from);
}

/**
* tipc_snprintf - append formatted output to print buffer
Expand All @@ -185,84 +53,3 @@ int tipc_snprintf(char *buf, int len, const char *fmt, ...)
va_end(args);
return i;
}

/**
* tipc_log_resize - change the size of the TIPC log buffer
* @log_size: print buffer size to use
*/
int tipc_log_resize(int log_size)
{
int res = 0;

spin_lock_bh(&print_lock);
kfree(TIPC_LOG->buf);
TIPC_LOG->buf = NULL;
if (log_size) {
if (log_size < TIPC_PB_MIN_SIZE)
log_size = TIPC_PB_MIN_SIZE;
res = TIPC_LOG->echo;
tipc_printbuf_init(TIPC_LOG, kmalloc(log_size, GFP_ATOMIC),
log_size);
TIPC_LOG->echo = res;
res = !TIPC_LOG->buf;
}
spin_unlock_bh(&print_lock);

return res;
}

/**
* tipc_log_resize_cmd - reconfigure size of TIPC log buffer
*/
struct sk_buff *tipc_log_resize_cmd(const void *req_tlv_area, int req_tlv_space)
{
u32 value;

if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);

value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
if (value > 32768)
return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
" (log size must be 0-32768)");
if (tipc_log_resize(value))
return tipc_cfg_reply_error_string(
"unable to create specified log (log size is now 0)");
return tipc_cfg_reply_none();
}

/**
* tipc_log_dump - capture TIPC log buffer contents in configuration message
*/
struct sk_buff *tipc_log_dump(void)
{
struct sk_buff *reply;

spin_lock_bh(&print_lock);
if (!TIPC_LOG->buf) {
spin_unlock_bh(&print_lock);
reply = tipc_cfg_reply_ultra_string("log not activated\n");
} else if (tipc_printbuf_empty(TIPC_LOG)) {
spin_unlock_bh(&print_lock);
reply = tipc_cfg_reply_ultra_string("log is empty\n");
} else {
struct tlv_desc *rep_tlv;
struct print_buf pb;
int str_len;

str_len = min(TIPC_LOG->size, 32768u);
spin_unlock_bh(&print_lock);
reply = tipc_cfg_reply_alloc(TLV_SPACE(str_len));
if (reply) {
rep_tlv = (struct tlv_desc *)reply->data;
tipc_printbuf_init(&pb, TLV_DATA(rep_tlv), str_len);
spin_lock_bh(&print_lock);
tipc_printbuf_move(&pb, TIPC_LOG);
spin_unlock_bh(&print_lock);
str_len = strlen(TLV_DATA(rep_tlv)) + 1;
skb_put(reply, TLV_SPACE(str_len));
TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len);
}
}
return reply;
}
Loading

0 comments on commit 869dd46

Please sign in to comment.