- Timestamp:
- 09/29/13 18:34:39 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ksyslog/trunk/ksyslog.c
r233 r234 55 55 set_fs(get_ds()); 56 56 57 if ( path_lookup(path, LOOKUP_OPEN|LOOKUP_FOLLOW, &nd))57 if (unlikely(path_lookup(path, LOOKUP_OPEN|LOOKUP_FOLLOW, &nd))) 58 58 file = filp_open(path, O_CREAT|O_WRONLY|O_APPEND|O_LARGEFILE, 0600); 59 59 else 60 60 file = filp_open(path, O_WRONLY|O_APPEND|O_LARGEFILE, 0); 61 61 62 if ( IS_ERR(file))63 goto out; 64 65 if ( S_ISDIR(file->f_path.dentry->d_inode->i_mode)) {62 if (unlikely(IS_ERR(file))) 63 goto out; 64 65 if (unlikely(S_ISDIR(file->f_path.dentry->d_inode->i_mode))) { 66 66 ksyslog_close(file); 67 67 file = ERR_PTR(-EISDIR); … … 69 69 } 70 70 71 if ( file->f_pos < 0) {71 if (unlikely(file->f_pos < 0)) { 72 72 ksyslog_close(file); 73 73 file = ERR_PTR(-EIO); … … 96 96 97 97 static void 98 ksyslog_drop_warning( struct ksyslog_entry *entry)98 ksyslog_drop_warning(const struct ksyslog_entry *entry) 99 99 { 100 100 pr_warn("dropped: %llu %s.%s %u.%u.%u.%u %.*s\n", … … 108 108 109 109 static int 110 ksyslog_format(char **buf, struct ksyslog_entry *entry)110 ksyslog_format(char **buf, const struct ksyslog_entry *entry) 111 111 { 112 112 *buf = kzalloc(54 + entry->length + 2, GFP_ATOMIC); 113 if ( *buf == NULL)113 if (unlikely(*buf == NULL)) 114 114 return -ENOMEM; 115 115 … … 124 124 125 125 static struct ksyslog_entry * 126 ksyslog_entry_create(struct sk_buff *skb, struct iphdr *iph, struct udphdr *udph) 126 ksyslog_entry_create(const struct sk_buff *skb, 127 const struct iphdr *iph, const struct udphdr *udph) 127 128 { 128 129 struct ksyslog_entry *entry; … … 148 149 149 150 entry = kzalloc(sizeof(*entry), GFP_ATOMIC); 150 if ( entry == NULL)151 if (unlikely(entry == NULL)) 151 152 return ERR_PTR(-ENOMEM); 152 153 153 154 length = skb->len - (start - skb->data); 154 155 entry->data = kzalloc(length, GFP_ATOMIC); 155 if ( entry->data == NULL) {156 if (unlikely(entry->data == NULL)) { 156 157 kfree(entry); 157 158 return ERR_PTR(-ENOMEM); 158 159 } 159 160 entry->facility = facility;161 entry->severity = severity;162 160 163 161 if (skb->tstamp.tv64) … … 166 164 do_gettimeofday(&entry->tv); 167 165 166 entry->facility = facility; 167 entry->severity = severity; 168 168 169 entry->daddr.addr32 = iph->daddr; 169 170 entry->saddr.addr32 = iph->saddr; … … 176 177 177 178 for (i = 0; i < length; i++) 178 if ( entry->data[i] == '\n')179 if (unlikely(entry->data[i] == '\n')) 179 180 entry->data[i] = ' '; 180 181 … … 193 194 ksyslog_entry_add(struct ksyslog_queue *queue, struct ksyslog_entry *entry) 194 195 { 195 if ( queue->length >= ksyslog_queue_max)196 if (unlikely(queue->length >= ksyslog_queue_max)) 196 197 return -ENOBUFS; 197 198 list_add_tail_rcu(&entry->list, &queue->head); … … 225 226 list_for_each_entry_safe(entry, next, &from->head, list) { 226 227 ksyslog_entry_del(from, entry, false); 227 if ( ksyslog_entry_add(to, entry)) {228 if (unlikely(ksyslog_entry_add(to, entry))) { 228 229 ksyslog_drop_warning(entry); 229 230 call_rcu(&entry->rcu, ksyslog_entry_free); … … 264 265 265 266 file = ksyslog_open(ksyslog_path); 266 if ( IS_ERR(file)) {267 if (unlikely(IS_ERR(file))) { 267 268 spin_unlock(&ksyslog_vfs_lock); 268 269 … … 281 282 282 283 length = ksyslog_format(&buf, entry); 283 if ( length < 0)284 if (unlikely(length < 0)) 284 285 goto restore; 285 286 286 if ( ksyslog_write(file, buf, length) < 0) {287 if (unlikely(ksyslog_write(file, buf, length) < 0)) { 287 288 kfree(buf); 288 289 goto restore; … … 295 296 restore: 296 297 spin_lock_bh(&ksyslog_queue_lock); 297 if ( ksyslog_entry_add(&ksyslog_queue, entry)) {298 if (unlikely(ksyslog_entry_add(&ksyslog_queue, entry))) { 298 299 ksyslog_drop_warning(entry); 299 300 call_rcu(&entry->rcu, ksyslog_entry_free); … … 301 302 spin_unlock_bh(&ksyslog_queue_lock); 302 303 } 304 303 305 ksyslog_close(file); 304 306 spin_unlock(&ksyslog_vfs_lock); … … 317 319 318 320 err = skb_linearize(skb); 319 if ( err)321 if (unlikely(err)) 320 322 goto out; 321 323 … … 323 325 udph = udp_hdr(skb); 324 326 325 if ( !skb_pull(skb, sizeof(*udph))) {327 if (unlikely(!skb_pull(skb, sizeof(*udph)))) { 326 328 err = -EINVAL; 327 329 goto out; … … 329 331 330 332 entry = ksyslog_entry_create(skb, iph, udph); 331 if ( IS_ERR(entry)) {333 if (unlikely(IS_ERR(entry))) { 332 334 err = PTR_ERR(entry); 333 335 goto out; … … 338 340 spin_unlock_bh(&ksyslog_queue_lock); 339 341 340 if ( err)342 if (unlikely(err)) 341 343 ksyslog_entry_free(&entry->rcu); 342 344 343 345 out: 344 if ( err)346 if (unlikely(err)) 345 347 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, IS_UDPLITE(sk)); 346 348
Note: See TracChangeset
for help on using the changeset viewer.