r1885: tighten the cache consistency with the ntprinters.tdb entry an the in memory...
authorGerald Carter <jerry@samba.org>
Wed, 18 Aug 2004 13:55:58 +0000 (13:55 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 15:52:23 +0000 (10:52 -0500)
(This used to be commit 540daf71d8ad189af5dd6d45aa1ce2b3d67da752)

source3/include/messages.h
source3/lib/messages.c
source3/printing/nt_printing.c
source3/printing/printing.c
source3/rpc_server/srv_spoolss_nt.c
source3/smbd/connection.c
source3/smbd/reply.c
source3/smbd/server.c

index 78f19fa0bdbde4679a966ae9cdab0fc33b9de29b..a87659f49849db84b99306d729f07d7e7a44181b 100644 (file)
 
 /* printing messages */
 /* #define MSG_PRINTER_NOTIFY  2001*/ /* Obsolete */
-#define MSG_PRINTER_DRVUPGRADE         2002
-#define MSG_PRINTER_NOTIFY2            2003
-#define MSG_PRINTERDATA_INIT_RESET     2004
-#define MSG_PRINTER_UPDATE             2005
+#define MSG_PRINTER_NOTIFY2            2002
+
+#define MSG_PRINTER_DRVUPGRADE         2101
+#define MSG_PRINTERDATA_INIT_RESET     2102
+#define MSG_PRINTER_UPDATE             2103
+#define MSG_PRINTER_MOD                        2104
 
 /* smbd messages */
 #define MSG_SMB_CONF_UPDATED 3001
@@ -67,6 +69,7 @@
 #define FLAG_MSG_GENERAL       0x0001
 #define FLAG_MSG_SMBD          0x0002
 #define FLAG_MSG_NMBD          0x0004
-#define FLAG_MSG_PRINTING      0x0008
+#define FLAG_MSG_PRINT_NOTIFY  0x0008
+#define FLAG_MSG_PRINT_GENERAL 0x0010
 
 #endif
index 8706ede70653cf6540ace0602f3ccda94988f29d..ded3ac95bb48414ece41aec6ad33032ddeae08b6 100644 (file)
@@ -576,8 +576,10 @@ BOOL message_send_all(TDB_CONTEXT *conn_tdb, int msg_type,
                msg_all.msg_flag = FLAG_MSG_GENERAL;
        else if (msg_type > 1000 && msg_type < 2000)
                msg_all.msg_flag = FLAG_MSG_NMBD;
-       else if (msg_type > 2000 && msg_type < 3000)
-               msg_all.msg_flag = FLAG_MSG_PRINTING;
+       else if (msg_type > 2000 && msg_type < 2100)
+               msg_all.msg_flag = FLAG_MSG_PRINT_NOTIFY;
+       else if (msg_type > 2100 && msg_type < 3000)
+               msg_all.msg_flag = FLAG_MSG_PRINT_GENERAL;
        else if (msg_type > 3000 && msg_type < 4000)
                msg_all.msg_flag = FLAG_MSG_SMBD;
        else
index 1c88bf27a88a1573f8b159eca427d0b2e335f8ba..b54e1f738d91faadff3681a5943420235e04541b 100644 (file)
@@ -365,6 +365,17 @@ BOOL nt_printing_init(void)
 
        message_register( MSG_PRINTERDATA_INIT_RESET, reset_all_printerdata );
 
+       /*
+        * register callback to handle invalidating the printer cache 
+        * between smbd processes.
+        */
+
+       message_register( MSG_PRINTER_MOD, receive_printer_mod_msg);
+
+       /* of course, none of the message callbacks matter if you don't
+          tell messages.c that you interested in receiving PRINT_GENERAL 
+          msgs.  This is done in claim_connection() */
+
 
        return True;
 }
@@ -3458,6 +3469,27 @@ static uint32 rev_changeid(void)
 #endif
 }
 
+/********************************************************************
+ Send a message to all smbds about the printer that just changed
+ ********************************************************************/
+static BOOL send_printer_mod_msg( char* printername )
+{
+       int len = strlen(printername);
+       
+       if (!len)
+               return False;
+
+       DEBUG(10,("send_printer_mod_msg: Sending message about printer change [%s]\n",
+               printername));
+               
+       /* spam everyone that we just changed this printer */
+       
+       message_send_all( conn_tdb_ctx(), MSG_PRINTER_MOD, printername, len+1, False, NULL );
+
+       return True;
+}
+
 /*
  * The function below are the high level ones.
  * only those ones must be called from the spoolss code.
@@ -3481,6 +3513,7 @@ WERROR mod_a_printer(NT_PRINTER_INFO_LEVEL printer, uint32 level)
         */
         
        invalidate_printer_hnd_cache( printer.info_2->sharename );
+       send_printer_mod_msg( printer.info_2->sharename );
        
        switch (level) {
                case 2:
index 10ca7e47e711d94baba0b8f4aba33c5ae8a65b2d..31cb0faa9b0379ac007d57d592c0e30d163106fd 100644 (file)
@@ -1183,7 +1183,7 @@ void start_background_queue(void)
                DEBUG(5,("start_background_queue: background LPQ thread started\n"));
 
                claim_connection( NULL, "smbd lpq backend", 0, False, 
-                       FLAG_MSG_GENERAL|FLAG_MSG_SMBD|FLAG_MSG_PRINTING );
+                       FLAG_MSG_GENERAL|FLAG_MSG_SMBD|FLAG_MSG_PRINT_GENERAL);
 
                if (!locking_init(0)) {
                        exit(1);
index ccff65688a7f862c5445d27cc5d699ee7555a3f8..5775b3ab491ec347e4d8b0a3586e906efc9dbe98 100644 (file)
@@ -180,7 +180,7 @@ static void srv_spoolss_replycloseprinter(int snum, POLICY_HND *handle)
                /* Tell the connections db we're no longer interested in
                 * printer notify messages. */
 
-               register_message_flags( False, FLAG_MSG_PRINTING );
+               register_message_flags( False, FLAG_MSG_PRINT_NOTIFY );
        }
 
        smb_connections--;
@@ -1194,12 +1194,6 @@ static void receive_notify2_message_list(int msg_type, pid_t src, void *msg, siz
                notify2_unpack_msg( &notify, &msg_tv, msg_ptr, msg_len );
                msg_ptr += msg_len;
 
-               /* we don't know if the change was from us or not so kill 
-                  any cached printer objects */
-
-               if ( notify.type == PRINTER_NOTIFY_TYPE )
-                       invalidate_printer_hnd_cache( notify.printer );
-               
                /* add to correct list in container */
                
                notify_msg_ctr_addmsg( &messages, &notify );
@@ -1226,6 +1220,22 @@ static void receive_notify2_message_list(int msg_type, pid_t src, void *msg, siz
        return;
 }
 
+/********************************************************************
+ callback to MSG_PRINTER_CHANGED.  When a printer is changed by 
+ one smbd, all of processes must clear their printer cache immediately.
+ ********************************************************************/
+
+void receive_printer_mod_msg(int msg_type, pid_t src, void *buf, size_t len)
+{
+       fstring printername;
+       
+       fstrcpy( printername, buf );
+       
+       DEBUG(10,("receive_printer_mod_msg: Printer change [%s]\n", printername ));
+       
+       invalidate_printer_hnd_cache( printername );
+}
+
 /********************************************************************
  Send a message to ourself about new driver being installed
  so we can upgrade the information for each printer bound to this
@@ -2641,7 +2651,7 @@ static BOOL srv_spoolss_replyopenprinter(int snum, const char *printer,
                message_register(MSG_PRINTER_NOTIFY2, receive_notify2_message_list);
                /* Tell the connections db we're now interested in printer
                 * notify messages. */
-               register_message_flags( True, FLAG_MSG_PRINTING );
+               register_message_flags( True, FLAG_MSG_PRINT_NOTIFY );
        }
 
        /* 
index 5bb76eb3bd83a6cf43093dcb2b015e26f3acc1d5..fc5fe9d7418df7c0c7193c23f2da54a9f4972406 100644 (file)
@@ -222,7 +222,6 @@ BOOL register_message_flags(BOOL doreg, uint32 msg_flags)
        }
 
        pcrec = (struct connections_data *)dbuf.dptr;
-       pcrec->bcast_msg_flags = msg_flags;
        if (doreg)
                pcrec->bcast_msg_flags |= msg_flags;
        else
index 74872eeea9f563ccc117f6e84dd54428aca4df7a..611fb04c19bb02f8b6dc4964f3507edc277ddc34 100644 (file)
@@ -242,7 +242,7 @@ int reply_special(char *inbuf,char *outbuf)
                reload_services(True);
                reopen_logs();
 
-               claim_connection(NULL,"",0,True,FLAG_MSG_GENERAL|FLAG_MSG_SMBD);
+               claim_connection(NULL,"",0,True,FLAG_MSG_GENERAL|FLAG_MSG_SMBD|FLAG_MSG_PRINT_GENERAL);
 
                already_got_session = True;
                break;
index 16281dd86cbaad0ed128aa62584265086336b2d4..0fe633bb9692468d65bc47ce775e5134a6f9b3b3 100644 (file)
@@ -846,6 +846,8 @@ void build_options(BOOL screen);
                exit(1);
 
        /* Setup the main smbd so that we can get messages. */
+       /* don't worry about general printing messages here */
+
        claim_connection(NULL,"",0,True,FLAG_MSG_GENERAL|FLAG_MSG_SMBD);
 
        /* only start the background queue daemon if we are